public async Task <IActionResult> PutCustomer([FromBody] CustomerDtoModel model) { var customer = await GetCustomerAsync(); if (customer.Orders.Any(x => x.Status != (byte)OrderStatus.InProcess)) { var orderInProgress = customer.Orders.FirstOrDefault(x => x.Status == (byte)OrderStatus.InProcess); customer = _mapper.Map <Customer>(model); customer.DateCreated = DateTime.UtcNow; customer.ApplicationUserId = Utilities.GetUserId(this.User); if (orderInProgress != null) { customer.Orders = new List <Order> { orderInProgress } } ; } else { _mapper.Map(model, customer); } _unitOfWork.Customers.Update(customer); _unitOfWork.SaveChanges(); return(Ok(_mapper.Map <CustomerViewModelForOrder>(customer))); }
public ActionResult Edit(int id) { CustomerDtoModel customer = _customerService.GetCustomerBy(id); if (customer == null) { return(RedirectToAction("Index")); } var customerRoles = _customerRoleService.GetCustomerRoles().Select(x => new SelectListItem { Text = x.Name, Value = x.Id.ToString(), Selected = x.Id == customer.CustomerRole.Id }).ToList(); CustomerModel model = new CustomerModel { Id = customer.Id, Username = customer.Username, Email = customer.Email, Active = customer.Active, CreationTime = customer.CreationTime, RoleId = customer.CustomerRole.Id, AvailableRoles = customerRoles }; return(View(model)); }
public ActionResult PopCustomer(string viewName, int id = 0) { CustomerModel model = new CustomerModel(); ViewBag.ViewName = viewName; if (id > 0) { CustomerDtoModel customer = _customerService.GetCustomerBy(id); if (customer == null) { return(RedirectToAction("List")); } model.Id = customer.Id; model.Username = customer.Username; model.Email = customer.Email; model.Active = customer.Active; model.AvailableRoles = _customerRoleService.GetCustomerRoles().Select(x => new SelectListItem { Value = x.Id.ToString(), Text = x.Name, Selected = x.Id == customer.CustomerRole.Id }).ToList(); } else { model.AvailableRoles = _customerRoleService.GetCustomerRoles().Select(x => new SelectListItem { Value = x.Id.ToString(), Text = x.Name }).ToList(); } return(PartialView("_PopCustomer", model)); }