public async Task <IActionResult> Create(string ids, int?locationId, string locationName) { return(await TryGetActionResultAsync(async() => { var model = new SaleCreateUpdateViewModel { AllowCreation = AllowCreation }; if (!LocationId.HasValue && !locationId.HasValue) { model.AllowChangeLocation = true; return View(model); } var result = await _saleService.CreateAsync(new SaleDto { LocationID = locationId ?? LocationId.Value, UserID = UserId, Date = DateTime.Now }, UserId); if (result.Status != ServiceResponseStatus.Success) { TempData["Error"] = "Не удалось оформить продажу."; return RedirectToAction("Index"); } if (!string.IsNullOrWhiteSpace(ids)) { var goodsIds = ids.Split(',').Select(id => Convert.ToInt32(id)); var goodsResult = await _saleService.AddGoodsAsync(goodsIds, null, result.Result, UserId); if (goodsResult.Status != ServiceResponseStatus.Success) { await _saleService.DeleteAsync(result.Result, UserId); TempData["Error"] = "Не удалось оформить продажу."; return RedirectToAction("Index"); } } TempData["Success"] = "Продажа оформлена. Для отмены нажмите \"Отменить продажу\". Для подтверждения оформления нажмите \"Подтвердить\"."; model.ID = result.Result; model.LocationID = locationId ?? LocationId.Value; model.LocationName = locationName ?? LocationName; model.AllowChangeLocation = false; return View(model); }, OnFault)); }