public async Task <IActionResult> PutEmployee([FromRoute] int id, [FromBody] Employee employee) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != employee.Id) { return(BadRequest()); } _context.Entry(employee).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!EmployeeExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> CreateUser(CreateUserViewModel model) { if (ModelState.IsValid) { await db.SaveChangesAsync(); User user = new User { Email = model.Email, UserName = model.Email }; var result = await _userManager.CreateAsync(user, model.Password); if (result.Succeeded) { var code = await _userManager.GenerateEmailConfirmationTokenAsync(user); var res = await _userManager.ConfirmEmailAsync(user, code); await _userManager.AddToRolesAsync(user, new List <string> { "user" }); return(RedirectToAction("Index")); } else { await db.SaveChangesAsync(); foreach (var error in result.Errors) { ModelState.AddModelError(string.Empty, error.Description); } } } return(View(model)); }
public async Task <IActionResult> PutWorkshopProblem([FromRoute] int id, [FromBody] WorkshopProblem workshopProblem) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != workshopProblem.Id) { return(BadRequest()); } _context.Entry(workshopProblem).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!WorkshopProblemExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> Create([Bind("Id,Name")] Department department) { if (ModelState.IsValid) { _context.Add(department); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(department)); }
public async Task <IActionResult> Create(Attendee attendee) { if (ModelState.IsValid) { _context.Add(attendee); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(attendee)); }
public async Task <IActionResult> Create(Order model) { try { HomeViewModel entryCache = memoryCache.Get <HomeViewModel>("Workshop"); if (ModelState.IsValid) { Order order = new Order() { carID = model.carID, dateReceipt = model.dateReceipt, dateCompletion = model.dateCompletion, workerID = model.workerID }; if (model.dateReceipt > model.dateCompletion) { ModelState.AddModelError("dateReceipt", "dateReceipt is not correct"); } await db.Orders.AddAsync(order); await db.SaveChangesAsync(); var workshop = service.GetHomeViewModel(); memoryCache.Set("Workshop", workshop); return(RedirectToAction("Index")); } } catch (Exception ex) { ModelState.AddModelError(ex.Source, "Invalid value for one of fields"); } return(View(model)); //HomeViewModel entryCache = memoryCache.Get<HomeViewModel>("Workshop"); //if (ModelState.IsValid) //{ // Order order = new Order() // { // carID = model.carID, // dateReceipt = model.dateReceipt, // dateCompletion = model.dateCompletion, // workerID = model.workerID // }; // await db.Orders.AddAsync(order); // await db.SaveChangesAsync(); // var workshop = service.GetHomeViewModel(); // memoryCache.Set("Workshop", workshop); // return RedirectToAction("Index"); //} //return View(model); }
public async Task <IActionResult> Create(CreateOwnerViewModel model) { int er = 0; if (ModelState.IsValid && (er = db.Owners.Count(p => p.driverLicense == model.driverLicense)) == 0) { Owner owner = new Owner { driverLicense = model.driverLicense, fioOwner = model.fioOwner, adress = model.adress, phone = model.phone }; await db.Owners.AddAsync(owner); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } if (er != 0) { ModelState.AddModelError("driverLicense", "Запись с таким именем уже есть"); } return(View(model)); }
/// <summary> /// Creates a new request /// </summary> /// <param name="request"></param> /// <returns></returns> public async Task <Request> Create(Request request, IFormFile file) { if (!Validate(request)) { throw new Exception("Failed to create a request"); } request.FilePath = _fileService.CreateFile(file); _context.Add(request); await _context.SaveChangesAsync(); return(request); }
public async Task <IActionResult> Create(CreatePartViewModel model) { int er = 0; if (ModelState.IsValid && (er = db.Parts.Count(p => p.partName == model.partName)) == 0) { Part part = new Part { partName = model.partName, price = model.price, descriptionPart = model.descriptionPart }; await db.Parts.AddAsync(part); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } if (er != 0) { ModelState.AddModelError("partName", "Запись с таким именем уже есть"); } return(View(model)); }
public async Task <IEnumerable <string> > Get() { ////////// var client = await _context.Clients.SingleOrDefaultAsync(m => m.Id == 2); if (client == null) { return(new[] { "" }); } await DeleteRestOfEntities(client); _context.Clients.Remove(client); await _context.SaveChangesAsync(); /// return(new string[] { "value1", "value2" }); }
public async Task <Product> Create(Product product, IFormFile file) { if (!Validate(product)) { throw new Exception("Failed to create the prodcut"); } product.ProductImage.Add(new ProductImage { FilePath = _fileService.CreateFile(file) }); _context.Add(product); await _context.SaveChangesAsync(); return(product); }
public async Task <IActionResult> Put([FromRoute] int id, [FromBody] string newPassword) { var employee = await _db.Employees.SingleOrDefaultAsync(m => m.Id == id); if (employee == null) { return(NotFound()); } var account = await _db.UsersAccounts.SingleOrDefaultAsync(u => u.EmployeeId == id); if (account == null) { return(NotFound()); } account.Password = newPassword; _db.Entry(account).State = EntityState.Modified; try { await _db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!EmployeeExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public static async Task DeleteObject(WorkshopObject obj, WorkshopContext context) { context.Objects.Remove(obj); await context.SaveChangesAsync(); }
public static async Task DeleteClient(Client client, WorkshopContext context) { context.Clients.Remove(client); await context.SaveChangesAsync(); }
public static async Task DeleteTask(WorkshopTask task, WorkshopContext context) { context.Tasks.Remove(task); await context.SaveChangesAsync(); }
public async Task InsertAsync(Seller obj) { await _context.AddAsync(obj); await _context.SaveChangesAsync(); }
public static async Task DeleteProblem(WorkshopProblem problem, WorkshopContext context) { context.Problems.Remove(problem); await context.SaveChangesAsync(); }