public IActionResult Create() { ViewData["CompanyId"] = new SelectList(db.Company.GetAll(), "Id", "CompanyName"); vmBranch vmBranch = new vmBranch(); return(PartialView("_CreateView", vmBranch)); }
public IActionResult Create(vmBranch vmBranch) { if (ModelState.IsValid) { Branch branch = new Branch() { Name = vmBranch.Name, Phone = vmBranch.Phone, Email = vmBranch.Email, Address = vmBranch.Address, Description = vmBranch.Description, CompanyId = vmBranch.CompanyId, IsActive = true, IsDeleted = false //ReservationId = vmBranch.ReservationId+500000, }; db.Branch.Add(branch); bool isUpdated = db.Save() > 0; if (isUpdated) { vmBranch.IsValid = true; vmBranch.Message = "Branch saved successfully!"; return(Json(vmBranch)); } vmBranch.IsValid = false; vmBranch.Message = "Branch can not be Updated. Something went wrong. Please try Again."; return(Json(vmBranch)); } vmBranch.IsValid = false; vmBranch.Message = "Validation Failed!. Please try Again with valid data."; return(Json(vmBranch)); }
public IActionResult Delete(vmBranch vmBranch) { if (ModelState.IsValid) { Branch branch = db.Branch.GetFirstOrDefault(c => c.Id == vmBranch.Id); branch.IsActive = false; branch.IsDeleted = true; db.Branch.Update(branch); //_db.Branch.Remove(branch); bool isUpdated = db.Save() > 0; if (isUpdated) { vmBranch.IsValid = true; vmBranch.Message = "Branch deleted successfully!"; return(Json(vmBranch)); } vmBranch.IsValid = false; vmBranch.Message = "Branch can not be deleted. Something went wrong. Please try Again."; } vmBranch.IsValid = false; vmBranch.Message = "Validation Failed!. Please try Again with valid data."; return(Json(vmBranch)); }
public IActionResult Edit(int id) { ViewData["CompanyId"] = new SelectList(db.Company.GetAll(), "Id", "CompanyName"); var branch = db.Branch.Get(id); vmBranch vmbranch = new vmBranch(); vmbranch.Id = branch.Id; vmbranch.Name = branch.Name; vmbranch.Email = branch.Email; vmbranch.Phone = branch.Phone; vmbranch.Description = branch.Description; vmbranch.CompanyId = branch.CompanyId; vmbranch.Address = branch.Address; return(PartialView("_EditView", vmbranch)); }
public IActionResult Edit(vmBranch vmBranch) { if (ModelState.IsValid) { Branch branch = db.Branch.GetFirstOrDefault(c => c.Id == vmBranch.Id); branch.Id = vmBranch.Id; branch.Name = vmBranch.Name; branch.Phone = vmBranch.Phone; branch.Email = vmBranch.Email; branch.Address = vmBranch.Address; branch.Description = vmBranch.Description; db.Branch.Update(branch); db.Save(); return(Json(vmBranch)); } vmBranch.IsValid = false; vmBranch.Message = "Validation Failed!. Please try Again with valid data."; return(Json(vmBranch)); }