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)); }
public async Task <IActionResult> DeleteAsync(int id) { var result = await _saleService.DeleteAsync(id); if (!result.Success) { return(BadRequest(result.Message)); } var saleResource = _mapper.Map <Sale, SaleResource>(result.Resource); return(Ok(saleResource)); }
public async Task <ActionResult> Delete(int id) { try { await _saleService.DeleteAsync(id).ConfigureAwait(false); return(RedirectToAction("Index")); } catch (Exception exception) { ViewBag.Error = exception.Message; return(RedirectToAction("Index")); } }
public async Task <IActionResult> Delete(string id) { //if (id == null) return BadRequest(); //not needed as middleware only calls this action if id is present; otherwise, it will try a different route, e.g. causing 405 (Method Not Allowed) if PUT request w/o id. if (_policyService.ContainsParentId(id)) { return(BadRequest(this.BadRequestDetails("Integrity validation failed.", $"At least one Policy is associated with Sale '{id}'."))); } //Note that to enforce validaed integrity above, this Delete action needs to constitute unit of work (currently not the case as uow is controlled by StorageController) //TODO: add the above validation to sales delete service bleow (i.e. remove dependency on policy service - see ctor); requires expansion to ServiceResult to discriminate between 400 & 404 responses (uow refactoring will still be needed to enforce data integrity). var svcRslt = await _saleService.DeleteAsync(id); if (!svcRslt.Success) { return(NotFound()); } return(NoContent()); }