public async Task <IActionResult> PutCollection([FromRoute] int id, [FromBody] CollectionDTO collectionDTO)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != collectionDTO.CollectionId)
            {
                return(BadRequest());
            }

            var collection = await collectionRepository.Edit(id, collectionDTO);

            if (collection == null)
            {
                return(BadRequest());
            }

            CollectionDTO cdto = new CollectionDTO();

            cdto.CollectionId       = collection.CollectionId;
            cdto.collectionName     = collection.collectionName;
            cdto.aestheticParameter = collection.aestheticParameter;
            cdto.products           = new List <ProductDTO>();

            foreach (CollectionProduct cp in collection.CollectionProducts)
            {
                ProductDTO productDTO = productToDTO(cp.Product);
                cdto.products.Add(productDTO);
            }

            return(Ok(cdto));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// The actual Work to be done.
        /// </summary>
        protected override void Execute()
        {
            collection collection = null;

            switch (Request.WellKnownModificationType)
            {
            case Core.Enums.WellKnownModificationType.Add:

                collection = Util.ConvertToCollection(Request.CollectionModel);

                CollectionRepository.Add(collection);
                CollectionRepository.Save();


                SubseryRepository.Add(new subsery()
                {
                    CollectionId  = collection.Id,
                    SubseriesName = "N/A"
                });

                SubseryRepository.Save();

                break;

            case Core.Enums.WellKnownModificationType.Edit:

                collection = CollectionRepository.GetCollecrtionToEdit(Request.CollectionModel.Id);

                collection = Util.ConvertToCollection(collection, Request.CollectionModel);

                CollectionRepository.Edit(collection);
                CollectionRepository.Save();

                break;

            default:
                break;
            }

            Response = new ResponseModel()
            {
                IsOperationSuccess = true
            };
        }