/// <summary> /// Create/Save the provided category in storage. /// Returns the category that was created wrapped in a ActionResult with the id it now has in the database. /// </summary> /// <param name="categoryToCreate"></param> /// <returns></returns> public ActionResult <Category> CreateCategory(Category categoryToCreate) { try { var createdCategory = _wsUnitOfWork.CategoryRepository.Create(categoryToCreate); _wsUnitOfWork.Commit(); return(ActionResult <Category> .GetSuccess(createdCategory, "Successfully create ")); } catch (Exception ex) { return(ActionResult <Category> .GetFailed($"[CreateCategory] Exception creating the category: " + ex.Message)); } }
/// <summary> /// Save the given new manufacturer in persistance. The returned manufacturer contains /// the id generated for the newly created manufacturer back to the calling code. /// </summary> /// <param name="manufacturer"></param> /// <returns></returns> public ActionResult <Manufacturer> Create(Manufacturer manufacturer) { try { var createdManufacturer = _unitOfWork.ManufacturerRepository.Create(manufacturer); _unitOfWork.Commit(); return(ActionResult <Manufacturer> .GetSuccess(createdManufacturer, "Successfully Created a new manufacturer")); } catch (Exception ex) { return(ActionResult <Manufacturer> .GetFailed($"Exception when creating manufacturer: {ex.Message}")); } }
public ActionResult <Product> Delete(int id) { try { var product = _unitOfWork.ProductRepository.GetById(id); if (product == null) { return(ActionResult <Product> .GetFailed("There is no such product")); } _unitOfWork.ProductRepository.DisableEntity(product); _unitOfWork.Commit(); return(ActionResult <Product> .GetSuccess(product, "Product deactivated")); } catch (Exception ex) { return(ActionResult <Product> .GetFailed($"[DeleteProduct] Exception/Failed when deleting/deactivating product. Exception: {ex.Message}")); } }
/// <summary> /// Create a new category with the given information for the given category id /// </summary> /// <param name="tagType"></param> /// <param name="categoryId"></param> /// <returns></returns> public ActionResult <TagType> CreateTagForCategory(TagType tagType, int categoryId) { try { var category = _unitOfWork.CategoryRepository.GetByCategoryId(categoryId); tagType.Categories = new List <Category> { category }; var createdTagType = _unitOfWork.TagTypeRepository.Create(tagType); _unitOfWork.Commit(); return(ActionResult <TagType> .GetSuccess(createdTagType)); } catch (Exception ex) { return(ActionResult <TagType> .GetFailed($"Exception: {ex.Message}")); } }