public IActionResult UserRegister(UpdateCustomerVM registerCustomer) { if (!ModelState.IsValid) { ShowToaster("Please fill required fields", ToasterLevel.Danger); return(RedirectToAction("Profile", new { customerId = registerCustomer.Id })); } ViewBag.Class = "inner-page"; var config = new MapperConfiguration(cfg => cfg.CreateMap <UpdateCustomerVM, RegisterCustomerDTO>()); var mapper = new Mapper(config); RegisterCustomerDTO dto = mapper.DefaultContext.Mapper.Map <RegisterCustomerDTO>(registerCustomer); var customer = _userService.UpdateCustomer(dto); if (customer != null) { TempData["isLogin"] = 1; TempData["uid"] = customer.Id; TempData["uname"] = customer.Name; ShowToaster("Profile updated successfully", ToasterLevel.Success); return(RedirectToAction("Profile", new { customerId = registerCustomer.Id })); } else { ShowToaster("Profile not updated", ToasterLevel.Danger); return(RedirectToAction("Profile", new { customerId = registerCustomer.Id })); } }
public JsonResult UpdateCustomer(UpdateCustomerVM vm) { try { Customer customer = _cus.GetById(vm.Id); customer.Modified = DateTime.Now; customer.ModifiedBy = SessionManager.ActiveUser.Id; customer.CompanyName = vm.CompanyName; customer.Contact = vm.Contact; customer.Caption = vm.Caption; customer.City = vm.City; customer.District = vm.District; customer.Email = vm.Email; customer.Phone = vm.Phone; customer.Description = vm.Description; _cus.Update(customer); return(Json(new { Result = true, Message = "Müşteri Başarıyla Güncellendi" })); } catch (Exception ex) { return(Json(new { Result = false, ex.Message })); } }
public IActionResult Profile(int customerId) { ViewBag.menu = JsonConvert.SerializeObject(GetCategory()); UpdateCustomerVM vm = new UpdateCustomerVM(); ViewBag.customerId = customerId; var user = _userService.GetUserById(customerId); vm.UserName = user.Name; vm.EmailId = user.EmailId; vm.Address = user.Address; vm.Contact = user.ContactNumber; vm.CountryId = user.CountryId; vm.StateId = user.StateId; vm.Id = user.Id; vm.Pincode = user.PinCode; vm.CountryList = _masterDataService.GetCountries().Select(x => new SelectListItem() { Text = x.Name, Value = x.Id.ToString() }).ToList(); vm.StateList = _masterDataService.GetStates(user.CountryId).Select(x => new SelectListItem() { Text = x.Name, Value = x.Id.ToString() }).ToList(); ViewBag.customerId = customerId; return(View(vm)); }
public async Task <IActionResult> UpdateCustomer(int id, [FromBody] UpdateCustomerVM customerVm) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var customerFromRepo = await _customerService.GetCustomer(id); if (customerFromRepo == null) { return(NotFound($"Could not find customer with an ID of {id}")); } _mapper.Map(customerVm, customerFromRepo); if (await _customerService.SaveAll()) { return(Ok("Customer Profile updated successfully")); } return(BadRequest($"Updating customer {customerVm.Fname} failed on save")); }