public ActionResult Data() { var model = ResolveModel(); string message; if (!model.CanProcessRequest(new System.Collections.Generic.Dictionary <string, object>(), out message)) { return(this.Json(new OperationStatusDTO() { Status = "failed", Message = message }, JsonRequestBehavior.AllowGet)); } var viewModel = model.GetViewModel(); var responseDTO = new OperationStatusDTO(); responseDTO.Status = "success"; if (viewModel == null) { responseDTO.Status = "failed"; } responseDTO.Data.Add("data", viewModel); return(this.Json(responseDTO, JsonRequestBehavior.AllowGet)); }
public IHttpActionResult Add(AddToBasketDTO model) { if (model.Quantity < 1) { var responseDTO = new OperationStatusDTO(); responseDTO.Status = "failed"; responseDTO.Message = "Quantity must be greater than 0"; return(this.Json(responseDTO)); } string variantSku = null; var product = Product.FirstOrDefault(x => x.Sku == model.Sku && x.VariantSku == null); if (product == null) { var responseDTO = new OperationStatusDTO(); responseDTO.Status = "failed"; responseDTO.Message = $"No product with SKU: '{ model.Sku}'"; return(this.Json(responseDTO)); } if (model.Variants != null && model.Variants.Any()) { var productQuery = Product.All().Where(x => x.Sku == model.Sku); foreach (var variant in model.Variants) { productQuery = productQuery.Where(x => x.ProductProperties.Any(y => y.Value == variant.Value && y.ProductDefinitionField.Name == variant.TypeName)); } var result = productQuery.FirstOrDefault(); if (result != null) { variantSku = result.VariantSku; } } TransactionLibrary.AddToBasket((int)model.Quantity, model.Sku, variantSku); return(Json(this.GetBasketModel())); }
public ActionResult Refresh() { var model = ResolveModel(); var viewModel = model.Refresh(); var parameters = new System.Collections.Generic.Dictionary <string, object>(); if (!model.CanProcessRequest(parameters, out var message)) { return(this.Json(new OperationStatusDTO { Status = "failed", Message = message }, JsonRequestBehavior.AllowGet)); } var responseDTO = new OperationStatusDTO(); responseDTO.Status = "success"; responseDTO.Data.Add("data", viewModel); return(Json(responseDTO, JsonRequestBehavior.AllowGet)); }
public ActionResult Save(AddressSaveViewModel addressRendering) { var model = ResolveModel(); var viewModel = model.GetViewModel(); string message; var parameters = new System.Collections.Generic.Dictionary <string, object>(); parameters.Add("addressRendering", addressRendering); parameters.Add("modelState", ModelState); var detailTemplateName = this.detailTemplateNamePrefix + this.TemplateName; if (!model.CanProcessRequest(parameters, out message)) { return(this.Json(new OperationStatusDTO() { Status = "failed", Message = message }, JsonRequestBehavior.AllowGet)); } if (ModelState.IsValid) { model.Save(addressRendering); return(this.Json(new OperationStatusDTO() { Status = "success" }, JsonRequestBehavior.AllowGet)); } else { var errorList = model.ErrorMessage(ModelState); var responseDTO = new OperationStatusDTO(); responseDTO.Status = "failed"; responseDTO.Data.Add("errors", errorList); return(this.Json(responseDTO, JsonRequestBehavior.AllowGet)); } }
public ActionResult Data() { var model = ResolveModel(); string message; var parameters = new System.Collections.Generic.Dictionary <string, object>(); if (!model.CanProcessRequest(parameters, out message)) { return(this.Json(new OperationStatusDTO() { Status = "failed", Message = message }, JsonRequestBehavior.AllowGet)); } var vm = model.GetViewModel(Url.Action("UpdateBasket"), Url.Action("RemoveOrderline")); var responseDTO = new OperationStatusDTO(); responseDTO.Status = "success"; responseDTO.Data.Add("data", vm); return(this.Json(responseDTO, JsonRequestBehavior.AllowGet)); }
public ActionResult Data(int?productId) { var model = ResolveModel(); string message; var parameters = new System.Collections.Generic.Dictionary <string, object>(); if (!model.CanProcessRequest(parameters, out message)) { return(this.Json(new OperationStatusDTO() { Status = "failed", Message = message }, JsonRequestBehavior.AllowGet)); } var vm = model.GetReviews(productId); var responseDTO = new OperationStatusDTO(); responseDTO.Status = "success"; responseDTO.Data.Add("Reviews", vm.Reviews); return(this.Json(responseDTO, JsonRequestBehavior.AllowGet)); }
public ActionResult CreateShipment(ShippingPickerViewModel createShipmentViewModel) { var model = ResolveModel(); string message; var parameters = new System.Collections.Generic.Dictionary <string, object>(); if (!model.CanProcessRequest(parameters, out message)) { return(this.PartialView("_Warning", message)); } var viewModel = model.GetViewModel(); model.CreateShipment(createShipmentViewModel); if (ModelState.IsValid) { return(this.Json(new OperationStatusDTO() { Status = "success" }, JsonRequestBehavior.AllowGet)); } else { var errorList = ModelState.ToDictionary( kvp => kvp.Key, kvp => kvp.Value.Errors.Select(e => e.ErrorMessage).ToArray() ); var responseDTO = new OperationStatusDTO(); responseDTO.Status = "failed"; responseDTO.Data.Add("errors", errorList); return(this.Json(responseDTO, JsonRequestBehavior.AllowGet)); } }