Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions WebStoreCoreApplication.sln
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ Global
{581700BA-91A1-4244-A194-0EF45BB2C613}.Release|Any CPU.ActiveCfg = Release|Any CPU
{581700BA-91A1-4244-A194-0EF45BB2C613}.Release|Any CPU.Build.0 = Release|Any CPU
{A927D081-0956-4C16-8F5A-10F933B3A19B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A927D081-0956-4C16-8F5A-10F933B3A19B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A927D081-0956-4C16-8F5A-10F933B3A19B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A927D081-0956-4C16-8F5A-10F933B3A19B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
4 changes: 3 additions & 1 deletion WebStoreCoreApplication/Controllers/BaseController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using WebStoreCoreApplication.Controllers.Infrastructure;

namespace WebStoreCoreApplication.Controllers
{
public class BaseController : Controller
{
[SimpleActionFilter]
public IActionResult Index()
{
return View();
}

public IActionResult _404()
public IActionResult NotPage()
{
return View();
}
Expand Down
94 changes: 71 additions & 23 deletions WebStoreCoreApplication/Controllers/EmployeeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,96 @@
using System.Linq;
using System.Net.Cache;
using System.Threading.Tasks;
using AspNetCore;
using Microsoft.AspNetCore.Mvc;
using WebStoreCoreApplication.Controllers.Infrastructure.Interfaces;
using WebStoreCoreApplication.ViewModels;
using WebStoreCoreApplication.Controllers;

namespace WebStoreCoreApplication.Controllers
{
[Route("peoples")]
public class EmployeeController : Controller
{
private readonly List<EmployeeViewModel> _employees = new List<EmployeeViewModel>

private readonly IEmployeeService _employeeService;

public EmployeeController(IEmployeeService employeeService)
{
new EmployeeViewModel
{
Id = 1,
Name = "Петр",
SName = "Петров",
FName = "Петрович",
Age = 33,
Position ="BOSS"
},
new EmployeeViewModel
{
Id = 2,
Name = "Фёдр",
SName = "Фёдоров",
FName = "Фёдорович",
Age = 25,
Position ="Программист"}
};
_employeeService = employeeService;
}

[Route("idx")]
public IActionResult Index()
{
return View();
}

[Route("all")]
public IActionResult Employees()
{
return View(_employees);
return View(_employeeService.GetAll());
}


[Route("{id}")]
public IActionResult EmployeeDetails(int id)
{
var employeeviewmodel = _employees.FirstOrDefault(x => x.Id == id);
if (employeeviewmodel == null) return NotFound();
var employeeviewmodel = _employeeService.GetByID(id);

if (employeeviewmodel == null)
return NotFound();

return View(employeeviewmodel);
}

[HttpPost]
[Route("edit/{id?}")]
public IActionResult Edit (EmployeeViewModel employeemodel) //int? id)
{
if (employeemodel.Id > 0)
{
var dbitem = _employeeService.GetByID(employeemodel.Id);

if (ReferenceEquals(dbitem, null))
return NotFound();
dbitem.IName = employeemodel.IName;
dbitem.FName = employeemodel.FName;
dbitem.OName = employeemodel.OName;
dbitem.Age = employeemodel.Age;
dbitem.Position = employeemodel.Position;
}
else
{
_employeeService.AddNew(employeemodel);
}
_employeeService.Commit();
return RedirectToAction(nameof(Employees));
/*
if (!id.HasValue)
return View(new EmployeeViewModel());

var model = _employeeService.GetByID(id.Value);

if (model == null)
return NotFound();

return View(model);
*/
}

[Route("delete/{id?}")]
public IActionResult Delete (int id)
{
var deluser = _employeeService.GetByID(id);
if (deluser.Id > 0 & (!ReferenceEquals(deluser, null)))
{
_employeeService.Delete(id);
}
return RedirectToAction(nameof(Employees));
}




}
}
39 changes: 39 additions & 0 deletions WebStoreCoreApplication/Controllers/Infrastructure/EmployeeWork.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using Microsoft.AspNetCore.Http;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace WebStoreCoreApplication.Controllers.Infrastructure
{
public class EmployeeWork
{
private const string correct = "qqq1234";
public RequestDelegate Next { get; }

public EmployeeWork(RequestDelegate next)
{
Next = next;
}

public async Task InvokeAsync(HttpContext context)
{
var token = context.Request.Query["usertoken"];

if (string.IsNullOrEmpty(token))
{
await Next.Invoke(context);
return;
}
if (token == correct)
{
await Next.Invoke(context);
}
else
{
await context.Response.WriteAsync("BAAAADDDD!!!!");
}
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WebStoreCoreApplication.ViewModels;

namespace WebStoreCoreApplication.Controllers.Infrastructure.Interfaces
{
public interface IEmployeeService
{
IEnumerable<EmployeeViewModel> GetAll();

EmployeeViewModel GetByID(int id);

void Commit();

void AddNew(EmployeeViewModel newmodel);

void Delete(int id);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WebStoreCoreApplication.Controllers.Infrastructure.Interfaces;
using WebStoreCoreApplication.ViewModels;

namespace WebStoreCoreApplication.Controllers.Infrastructure.Services
{
public class InMemoryEmployeeServices : IEmployeeService
{
private readonly List<EmployeeViewModel> _employees = new List<EmployeeViewModel>
{
new EmployeeViewModel
{
Id = 1,
IName = "Петр",
FName = "Петров",
OName = "Петрович",
Age = 33,
Position ="BOSS"
},
new EmployeeViewModel
{
Id = 2,
IName = "Фёдр",
FName = "Фёдоров",
OName = "Фёдорович",
Age = 25,
Position ="Программист"}
};

public void AddNew(EmployeeViewModel newmodel)
{
newmodel.Id = _employees.Max(e => e.Id) + 1;
_employees.Add(newmodel);
}

public void Commit()
{
//
}

public void Delete(int id)
{
var employee = GetByID(id);
if (employee is null)
return;

_employees.Remove(employee);
}

public IEnumerable<EmployeeViewModel> GetAll()
{
return _employees;
}

public EmployeeViewModel GetByID(int id)
{
return _employees.FirstOrDefault(e => e.Id.Equals(id));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using Microsoft.AspNetCore.Mvc.Filters;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace WebStoreCoreApplication.Controllers.Infrastructure
{
public class SimpleActionFilter : Attribute, IActionFilter
{
public void OnActionExecuting(ActionExecutingContext context)
{
// throw new NotImplementedException();
return;
}

public void OnActionExecuted(ActionExecutedContext context)
{
// throw new NotImplementedException();
return;
}

}
}
41 changes: 41 additions & 0 deletions WebStoreCoreApplication/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.CodeAnalysis.Options;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using WebStoreCoreApplication.Controllers.Infrastructure;
using WebStoreCoreApplication.Controllers.Infrastructure.Interfaces;
using WebStoreCoreApplication.Controllers.Infrastructure.Services;

namespace WebStoreCoreApplication
{
Expand All @@ -23,6 +27,15 @@ public Startup(IConfiguration configuration)
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();

/*
services.AddMvc(options =>
{
options.Filters.Add(typeof(SimpleActionFilter));
});
*/

services.AddSingleton<IEmployeeService, InMemoryEmployeeServices>();
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
Expand All @@ -37,6 +50,9 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)

var hello = _configuration["CustomeHelloWorld"];

//app.Map("/Index", CustomIndexHandler);
app.UseMiddleware<EmployeeWork>();

app.UseRouting();

app.UseEndpoints(endpoints =>
Expand All @@ -52,6 +68,31 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
*/
});
}
/*
private void CustomIndexHandler(IApplicationBuilder app)
{
app.Run(async context =>
{
await context.Response.WriteAsync("Index Custom!!!");
});
}

private void UseMiddlewareSample(IApplicationBuilder app)
{
app.Use(async (context, next) =>
{
bool isError = false;
if (isError)
{
await context.Response.WriteAsync("Errrrrrrrooooooorrrrr!!!!");
}
else
{
await next.Invoke();
}
});
}
*/
}
}

4 changes: 2 additions & 2 deletions WebStoreCoreApplication/ViewModels/EmployeeViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ namespace WebStoreCoreApplication.ViewModels
public class EmployeeViewModel
{
public int Id { get; set; }
public string Name { get; set;}
public string SName { get; set;}
public string IName { get; set;}
public string FName { get; set;}
public string OName { get; set;}
public int Age { get; set;}
public string Position { get; set;}
}
Expand Down
2 changes: 1 addition & 1 deletion WebStoreCoreApplication/Views/Base/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
<section>
<div class="container">
<div class="row">
@Html.Partial("Partial/LeftBar")<!--Leftbar-->
@await Html.PartialAsync("Partial/LeftBar")<!--Leftbar-->

<div class="col-sm-9 padding-right">
<div class="features_items">
Expand Down
Loading