public async Task <IActionResult> DeleteCollection([FromRoute] int id)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var collection = await collectionRepository.Remove(id);

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

            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
        public async Task <bool> DeleteCalendarCollection(Dictionary <string, string> propertiesAndHeaders,
                                                          HttpResponse response)
        {
            #region Extracting Properties

            string url;
            propertiesAndHeaders.TryGetValue("url", out url);

            #endregion

            //The delete method default status code
            response.StatusCode = (int)HttpStatusCode.NoContent;
            //If the collection already is gone it is treated as a successful operation.
            if (!StorageManagement.ExistCalendarCollection(url))
            {
                return(true);
            }

            //The collection is retrieve and if something unexpected happened an internal error is reflected.
            var collection = _collectionRespository.Get(url);
            if (collection == null)
            {
                StorageManagement.DeleteCalendarCollection(url);
                response.StatusCode = (int)HttpStatusCode.InternalServerError;
                return(false);
            }


            await _collectionRespository.Remove(collection);

            return(StorageManagement.DeleteCalendarCollection(url));
        }