public async Task <IActionResult> Update([FromBody] BranchUpdateViewModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (model.branchId <= 0) { return(BadRequest()); } var branch = await _context.Branches.FirstOrDefaultAsync(b => b.branchId == model.branchId); if (branch == null) { return(NotFound()); } branch.branchname = model.branchname; branch.branchdesc = model.branchdesc; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { return(BadRequest()); } return(Ok()); }
public IActionResult Update(int id) { //get the Branch from database Branch bra = _branchDataService.GetSingle(p => p.BranchId == id); BranchUpdateViewModel vm = new BranchUpdateViewModel { BranchId = id, Name = bra.Name, Address = bra.Address, Phone = bra.Phone, }; return(View(vm)); }
public IActionResult Update(BranchUpdateViewModel vm, int BranchId) { if (ModelState.IsValid) { Branch b = new Branch { BranchId = BranchId, Name = vm.Name, Address = vm.Address, Phone = vm.Phone, }; _branchDataService.Update(b); return(RedirectToAction("Index", "Branch")); } return(View(vm)); }