public async Task <ActionResult <GetSaleInfoUtilityModel> > CancelOrder(CancelOrderInputModel inputModel) { try { var saleInfoModel = await this.GetSaleInfo(inputModel.SaleId); if (saleInfoModel == null) { return(this.NotFound()); } var currentUserId = this.GetUserId(this.User); if (saleInfoModel.BuyerId != currentUserId) { return(this.Forbid()); } await this.salesService.CancelOrder <SaleStatusResourceModel>(inputModel.SaleId, currentUserId); await this.saleLogsService.ClearSaleLogs(saleInfoModel.Id); await this.saleLogHubContext.Clients.Group(saleInfoModel.Id.ToString()) .RecieveLogNotification("Order was canceled by buyer!"); await this.saleChatService.ClearSaleMessages(saleInfoModel.Id); return(saleInfoModel); } catch (Exception ex) { this.loggerService.LogException(ex); return(this.BadRequest()); } }
public JsonResult CancelOrder(CancelOrderInputModel inputModel) { try { Assert.ArgumentNotNull(inputModel, nameof(inputModel)); var validationResult = this.CreateJsonResult <CancelOrderApiModel>(); if (validationResult.HasErrors) { return(Json(validationResult, JsonRequestBehavior.AllowGet)); } var response = OrderManager.CancelOrder(CommerceUserContext.Current.UserId, inputModel); var result = new CancelOrderApiModel(response.ServiceProviderResult); return(Json(result, JsonRequestBehavior.AllowGet)); } catch (Exception e) { return(Json(new ErrorApiModel("CancelOrder", e), JsonRequestBehavior.AllowGet)); } }
public JsonResult CancelOrder(CancelOrderInputModel inputModel) { try { Assert.ArgumentNotNull(inputModel, "inputModel"); var validationResult = new CancelOrderBaseJsonResult(); this.ValidateModel(validationResult); if (validationResult.HasErrors) { return(Json(validationResult, JsonRequestBehavior.AllowGet)); } var response = this.OrderManager.CancelOrder(this.CurrentStorefront, this.CurrentVisitorContext, inputModel); var result = new CancelOrderBaseJsonResult(response.ServiceProviderResult); return(Json(result, JsonRequestBehavior.AllowGet)); } catch (Exception e) { CommerceLog.Current.Error("CancelOrder", this); return(Json(new BaseJsonResult("CancelOrder", e), JsonRequestBehavior.AllowGet)); } }
public ManagerResponse <VisitorCancelOrderResult, bool> CancelOrder(string userId, CancelOrderInputModel inputModel) { Assert.ArgumentNotNull(inputModel, nameof(inputModel)); Assert.ArgumentNotNullOrEmpty(inputModel.OrderId, nameof(inputModel.OrderId)); if (StorefrontContext.Current == null) { throw new InvalidOperationException("Cannot be called without a valid storefront context."); } var request = new VisitorCancelOrderRequest(inputModel.OrderId, userId, StorefrontContext.Current.ShopName) { OrderLineExternalIds = inputModel.OrderLineExternalIds }; var result = OrderServiceProvider.VisitorCancelOrder(request); result.WriteToSitecoreLog(); return(new ManagerResponse <VisitorCancelOrderResult, bool>(result, result.Success)); }
/// <summary> /// Cancels one or more items from an existing order. /// </summary> /// <param name="storefront">The storefront context.</param> /// <param name="visitorContext">The visitor context.</param> /// <param name="inputModel">The order cancellation input model.</param> /// <returns>The result of the operation.</returns> public ManagerResponse <VisitorCancelOrderResult, bool> CancelOrder([NotNull] CommerceStorefront storefront, [NotNull] VisitorContext visitorContext, CancelOrderInputModel inputModel) { Assert.ArgumentNotNull(storefront, "storefront"); Assert.ArgumentNotNull(visitorContext, "visitorContext"); Assert.ArgumentNotNull(inputModel, "inputModel"); Assert.ArgumentNotNullOrEmpty(inputModel.OrderId, "inputModel.OrderId"); var request = new VisitorCancelOrderRequest(inputModel.OrderId, visitorContext.GetCustomerId(), storefront.ShopName); request.OrderLineExternalIds = inputModel.OrderLineExternalIds; var result = this.OrderServiceProvider.VisitorCancelOrder(request); if (!result.Success) { Helpers.LogSystemMessages(result.SystemMessages, result); } return(new ManagerResponse <VisitorCancelOrderResult, bool>(result, result.Success)); }