public async Task <IActionResult> SubmitOrder([FromBody] OrderViewModel orderViewModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (orderViewModel.DeliveryDataId == null && orderViewModel.DeliveryTypeId != 1) { _context.DeliveryDatas.Add(orderViewModel.DeliveryData); _context.SaveChanges(); orderViewModel.DeliveryDataId = orderViewModel.DeliveryData.Id; orderViewModel.DeliveryData = null; } if (orderViewModel.InvoiceDataId == null && orderViewModel.IsInvoice) { _context.InvoiceDatas.Add(orderViewModel.InvoiceData); _context.SaveChanges(); orderViewModel.InvoiceDataId = orderViewModel.InvoiceData.Id; orderViewModel.InvoiceData = null; } var order = Mapper.Map <Order>(orderViewModel); order.PaymentStatusId = 1; foreach (var photo in order.Photos) { _context.Photos.Add(photo); } _context.Orders.Add(order); var client = await _userManager.Users.Where(e => e.Id == orderViewModel.UserId).FirstOrDefaultAsync(); client.OrdersAmount = client.OrdersAmount + 1; await _context.SaveChangesAsync(); return(new OkObjectResult("Order added correctly!")); }
public IActionResult DeleteUser(string id) { if (ModelState.IsValid) { if (id == null) { return(new BadRequestObjectResult("Wrong User Id!")); } _context.UserLogins.RemoveRange(_context.UserLogins.Where(ul => ul.UserId == id)); _context.UserRoles.RemoveRange(_context.UserRoles.Where(ur => ur.UserId == id)); _context.Users.Remove(_context.Users.Single(usr => usr.Id == id)); _context.SaveChanges(); return(new OkObjectResult("User removed correctly")); } return(new BadRequestObjectResult("Wrong User model!")); }