//сохранить новую либо обновить существующую запись в БД public Guid SaveArticle(RegisteViewModel entity) { if (entity.id == default) { context.Entry(entity).State = EntityState.Added; context.RegisteViewModel.Add(entity); } else { context.Entry(entity).State = EntityState.Modified; } context.SaveChanges(); return(entity.id); }
public ActionResult Edit(int id, Contract contract) { if (HttpContext.Session.GetString("actions") == "admin") { try { using (appDBContent) { contract.id = id; appDBContent.Entry(contract).State = EntityState.Modified; appDBContent.SaveChanges(); } return(RedirectToAction("Index")); } catch { ViewBag.Message = "Данные некорректны!"; return(View()); } } else { return(RedirectToRoute(new { controller = "Employee", action = "Login" })); } }
public ActionResult Edit(int id, DepositType depositType) { if (HttpContext.Session.GetString("actions") == "admin") { try { using (appDBContent) { if (depositType.capitalization > 0 && depositType.minMoney > 0 && depositType.percent > 0 && depositType.percent < 100 && depositType.period > 0 && depositType.maxMoney > depositType.minMoney) { depositType.id = id; appDBContent.Entry(depositType).State = EntityState.Modified; appDBContent.SaveChanges(); } else { ViewBag.Message = "Данные некорректны!"; return(View()); } } return(RedirectToAction("Index")); } catch { ViewBag.Message = "Данные некорректны!"; return(View()); } } else { return(RedirectToRoute(new { controller = "Employee", action = "Login" })); } }
public async Task <IActionResult> AddSneaker(Sneaker obj) { try { if (ModelState.IsValid) { if (obj.Id == 0) { _appDBContent.Sneakers.Add(obj); await _appDBContent.SaveChangesAsync(); } else { _appDBContent.Entry(obj).State = EntityState.Modified; await _appDBContent.SaveChangesAsync(); } return(RedirectToAction("SneakersList")); } return(View()); } catch (Exception ex) { return(RedirectToAction("SneakersList")); } }
public async Task <ActionResult <Bike> > Put(int id, Bike model) { try { model.id = id; var oldBike = await _appDbContent.Bike.FirstOrDefaultAsync(x => x.id == id); if (oldBike == null) { return(NotFound()); } _appDbContent.Entry(oldBike).CurrentValues.SetValues(model); await _appDbContent.SaveChangesAsync(); return(Ok()); } catch (Exception e) { return(this.StatusCode(StatusCodes.Status500InternalServerError, e.InnerException)); } }
public ActionResult Edit(int id, Deposit deposit) { if (HttpContext.Session.GetString("actions") == "admin") { try { using (appDBContent) { deposit.id = id; DepositType depType = new DepositType(); depType = appDBContent.DepositType.Where(x => x.id == deposit.depositTypeID).FirstOrDefault(); if (depType != null) { if (deposit.initialMoney >= depType.minMoney && deposit.initialMoney <= depType.maxMoney) { deposit.plannedFinalAmountOfMoney = this.finalAmountOfMoney(deposit.initialMoney, depType.period, depType.capitalization, depType.percent); appDBContent.Entry(deposit).State = EntityState.Modified; appDBContent.SaveChanges(); } else { ViewBag.Message = "Сумма не подходит для данного типа вклада!"; return(View()); } } } return(RedirectToAction("Index")); } catch { return(View()); } } else { return(RedirectToRoute(new { controller = "Employee", action = "Login" })); } }
public ActionResult Edit(int id, Employee emp) { if (HttpContext.Session.GetString("actions") == "admin") { try { using (appDBContent) { List <Employee> empl = new List <Employee>(); empl = appDBContent.Employee.Where(x => x.EmployeeLogin == emp.EmployeeLogin).ToList(); if (empl.Count == 0) { emp.id = id; emp.isAdmin = false; appDBContent.Entry(emp).State = EntityState.Modified; appDBContent.SaveChanges(); } else { ViewBag.Message = "Сотрудник уже зарегистрирован в системе!"; return(View()); } } return(RedirectToAction("Index")); } catch { return(View()); } } else { return(RedirectToAction("Login")); } }