Esempio n. 1
0
 /// <summary>
 /// Maps Name, OrganizationId
 /// </summary>
 /// <param name="dto"></param>
 /// <returns></returns>
 /// <exception cref="NullReferenceException"></exception>
 public static DALCategoryDTO FromBLL(BLLCategoryDTO dto)
 {
     if (dto == null)
     {
         throw new NullReferenceException("Can't map, BLLCategoryDTO is null");
     }
     return(new DALCategoryDTO()
     {
         Name = dto.CategoryName,
         OrganizationId = dto.OrganizationId
     });
 }
Esempio n. 2
0
 /// <summary>
 /// Maps id, name, Products(id, name, price, description)
 /// </summary>
 /// <param name="dto"></param>
 /// <returns></returns>
 /// <exception cref="NullReferenceException"></exception>
 public static CategoryDTO FromBLL(BLLCategoryDTO dto)
 {
     if (dto == null)
     {
         throw new NullReferenceException("Can't map, BLLCategoryDTO is null");
     }
     return(new CategoryDTO()
     {
         Id = dto.CategoryId,
         Name = dto.CategoryName,
         Products = dto.Products
                    .Select(ProductMapper.FromBLL)
                    .ToList()
     });
 }
Esempio n. 3
0
        public async Task <bool> AddCategoryAsync(BLLCategoryDTO categoryDTO)
        {
            var organization = await Uow.Organizations.Exists(categoryDTO.OrganizationId);

            if (!organization)
            {
                return(false);
            }


            await Uow.Categories.AddAsync(CategoryMapper.FromBLL(categoryDTO));

            await Uow.SaveChangesAsync();

            return(true);
        }
Esempio n. 4
0
        public async Task <IActionResult> Create(CreateCategoryViewModel vm)
        {
            if (ModelState.IsValid)
            {
                var category = new BLLCategoryDTO
                {
                    CategoryName   = vm.CategoryName,
                    OrganizationId = vm.OrganizationId
                };

                var result = await _bll.CategoryService.AddCategoryAsync(category);

                if (result == false)
                {
                    return(BadRequest("Something went wrong while adding the category"));
                }
            }

            return(RedirectToAction("Organization", "Dashboard", new { Id = vm.OrganizationId }));
        }