public ActionResult Edit(CreateCustomerCodeViewModel model) { try { if (!ModelState.IsValid) { return(View(model)); } var customerCode = _mapper.Map <CustomerCode1>(model); customerCode.UpdatedAt = DateTime.Now; var isSuccess = _repo.Update(customerCode); if (!isSuccess) { ModelState.AddModelError("", "Something Went Wrong"); return(View(model)); } return(RedirectToAction(nameof(Index))); } catch { ModelState.AddModelError("", "Something Went Wrong"); return(View()); } }
public ActionResult Create(CreateCustomerCodeViewModel model) { try { if (!ModelState.IsValid) { return(View(model)); } var customerCode = _mapper.Map <CustomerCode1>(model); // customerCode.CustomerCodeId = 1; customerCode.CreatedAt = DateTime.Now; customerCode.UpdatedAt = DateTime.Now; //customerCode.ProductId = model.ProductId var isSuccess = _repo.Create(customerCode); if (!isSuccess) { ModelState.AddModelError("", "Something Went Wrong"); return(View(model)); } var Id = model.ProductId; // return RedirectToAction(nameof(Index)); return(RedirectToAction("Create", "ErrorMessage", new { ProductId = Id })); } catch (Exception ex) { return(View()); } }
// GET: CustomerCOde/Create public ActionResult Create(int id) { var customerViewModel = new CreateCustomerCodeViewModel(); customerViewModel.ProductId = id; return(View(customerViewModel)); }
public ActionResult Delete(int id, CreateCustomerCodeViewModel model) { try { // TODO: Add delete logic here var customerCode = _repo.Find(id); if (customerCode == null) { return(NotFound()); } var isSuccess = _repo.Delete(customerCode); if (!isSuccess) { return(View(model)); } return(RedirectToAction(nameof(Index))); } catch { return(View(model)); } }