public async Task CreateBranch(CreateBranchViewModel request, CancellationToken cancellationToken = default) { var entity = request.Cast(); await _context.Branches.AddAsync(entity, cancellationToken); await _context.SaveChangesAsync(cancellationToken); }
public ActionResult Detail(long?id) { var branch = _db.Branch.FirstOrDefault(p => p.Id == id); if (branch == null) { return(Redirect("Index")); } CreateBranchViewModel model = new CreateBranchViewModel() { BranchName = branch.Name }; return(View(model)); }
public ActionResult Create(CreateBranchViewModel model) { if (!ModelState.IsValid) { ModelState.AddModelError("Error", "Error! Please try again!"); return(View(model)); } Branch branch = new Branch() { Name = model.BranchName }; _db.Branch.Add(branch); _db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Detail(long?id, CreateBranchViewModel model) { if (!ModelState.IsValid) { ModelState.AddModelError("Error", "Error! Please try again!"); return(View(model)); } var branch = _db.Branch.FirstOrDefault(p => p.Id == id); if (branch == null) { return(Redirect("Index")); } branch.Name = model.BranchName; _db.SaveChanges(); return(RedirectToAction("Index")); }
public async Task <ActionResult> CreateBranch([FromBody] CreateBranchViewModel request) { await _branchManagement.CreateBranch(request); return(Ok()); }