Example #1
0
        /// <summary>
        /// All products which assigned to deleting category are moved to default category
        /// </summary>
        public bool DeleteCatalog(int userId, string catalogName)
        {
            // Get result of the delete action
            var result = catalogName != "Domyślny" &&
                         _catalogRepository.DeleteCatalog(userId, catalogName);

            // If something was wrong return false;
            if (!result)
            {
                return(false);
            }

            // Otherwise
            // Get products of the deleted category
            var products = _productRepository.GetUserProductsByCatalogId(userId, null);

            // Get id of the default category
            var defaultCatalogId = _catalogRepository.FindCatalogIdByName("Domyślny", userId);

            // For every product without category...
            foreach (var product in products)
            {
                // assign default category
                product.CatalogId = defaultCatalogId;
                _productRepository.Update(product);
                _productRepository.SaveAll();
            }

            return(true);
        }
Example #2
0
 public ActionResult Delete(CatalogViewModel catalog)
 {
     try
     {
         _catalogRepository.DeleteCatalog(catalog.SelectedCatalog.Id);
         return(RedirectToAction(nameof(Index)));
     }
     catch (Exception e)
     {
         return(View("Error"));
     }
 }
Example #3
0
        public HttpStatusCode DeleteCatalog(int catalogId)
        {
            var response = _catalogRepository.DeleteCatalog(catalogId);

            switch (response)
            {
            case HttpStatusCode.OK:
                return(HttpStatusCode.OK);

            case HttpStatusCode.InternalServerError:
                return(HttpStatusCode.InternalServerError);

            default:
                return(HttpStatusCode.NotFound);
            }
        }
Example #4
0
 public async Task Delete(long id)
 {
     _catalogRepo.DeleteCatalog(id);
     await _catalogRepo.SaveAll();
 }