public virtual HttpResponseMessage EditOption(HttpRequestMessage request, SpecificationAttributeOptionVM model)
        {
            return(CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = request.CreateErrorResponse(HttpStatusCode.NotFound, "No specification attribute option found with the specified id");
                if (!ModelState.IsValid)
                {
                    response = request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
                }
                else
                {
                    var sao = _specificationAttributeService.GetSpecificationAttributeOptionById(model.Id);

                    if (sao != null)
                    {
                        sao = model.ToEntity(sao);
                        //clear "Color" values if it's disabled
                        if (!model.EnableColorSquaresRgb)
                        {
                            sao.ColorSquaresRgb = null;
                        }

                        _specificationAttributeService.UpdateSpecificationAttributeOption(sao);

                        _baseService.Commit();
                        response = request.CreateResponse <SpecificationAttributeOptionVM>(HttpStatusCode.OK, model);
                    }
                }
                return response;
            }));
        }
        public HttpResponseMessage CreateOption(HttpRequestMessage request, SpecificationAttributeOptionVM model)
        {
            return(CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = request.CreateErrorResponse(HttpStatusCode.NotFound, "Invalid specification attribute id.");
                if (!ModelState.IsValid)
                {
                    response = request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
                }
                else
                {
                    var specificationAttribute = _specificationAttributeService.GetSpecificationAttributeById(model.SpecificationAttributeId);
                    if (specificationAttribute != null)
                    {
                        var sao = model.ToEntity();
                        //clear "Color" values if it's disabled
                        if (!model.EnableColorSquaresRgb)
                        {
                            sao.ColorSquaresRgb = null;
                        }

                        _specificationAttributeService.InsertSpecificationAttributeOption(sao);

                        _baseService.Commit();
                        response = request.CreateResponse <SpecificationAttributeOption>(HttpStatusCode.Created, sao);
                    }
                }
                return response;
            }));
        }
        public HttpResponseMessage GetOptionListBySAId(HttpRequestMessage request, int specificationAttributeId, string getType = "list")
        {
            return(CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = request.CreateErrorResponse(HttpStatusCode.NotFound, "Invalid specification attribute id.");
                if (getType.Equals("create", StringComparison.InvariantCultureIgnoreCase))
                {
                    var specificationAttribute = _specificationAttributeService.GetSpecificationAttributeById(specificationAttributeId);
                    if (specificationAttribute != null)
                    {
                        var model = new SpecificationAttributeOptionVM
                        {
                            SpecificationAttributeId = specificationAttributeId
                        };
                        response = request.CreateResponse <SpecificationAttributeOptionVM>(HttpStatusCode.OK, model);
                    }
                }
                else if (getType.Equals("list", StringComparison.InvariantCultureIgnoreCase))
                {
                    var options = _specificationAttributeService.GetSpecificationAttributeOptionsBySpecificationAttribute(specificationAttributeId);
                    if (options != null)
                    {
                        var gridModel = new DataSourceResult
                        {
                            Data = options.Select(x =>
                            {
                                var model = x.ToModel();
                                //in order to save performance to do not check whether a product is deleted, etc
                                model.NumberOfAssociatedProducts = _specificationAttributeService.GetProductSpecificationAttributeCount(0, x.Id);
                                return model;
                            }),
                            Total = options.Count()
                        };

                        response = request.CreateResponse <DataSourceResult>(HttpStatusCode.OK, gridModel);
                    }
                }

                return response;
            }));
        }
Пример #4
0
 public static SpecificationAttributeOption ToEntity(this SpecificationAttributeOptionVM model, SpecificationAttributeOption destination)
 {
     return(model.MapTo(destination));
 }
Пример #5
0
 public static SpecificationAttributeOption ToEntity(this SpecificationAttributeOptionVM model)
 {
     return(model.MapTo <SpecificationAttributeOptionVM, SpecificationAttributeOption>());
 }