Exemplo n.º 1
0
        public async Task <IActionResult> Post([FromBody] ProductCategoryDtoModel model)
        {
            //if (!(await _authorizationService.AuthorizeAsync(this.User, new string[] { }, Authorization.Policies.AssignAllowedRolesPolicy)).Succeeded)
            //    return new ChallengeResult();

            var category = _mapper.Map <ProductCategory>(model);
            await _unitOfWork.ProductCategories.PostAsync(category);

            category.DateCreated  = DateTime.UtcNow;
            category.DateModified = DateTime.UtcNow;
            _unitOfWork.SaveChanges();
            return(Ok(_mapper.Map <ProductCategoryViewModel>(category)));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Put(int id, [FromBody] ProductCategoryDtoModel model)
        {
            //if (!(await _authorizationService.AuthorizeAsync(this.User, new string[] { }, Authorization.Policies.AssignAllowedRolesPolicy)).Succeeded)
            //    return new ChallengeResult();
            var category = await _unitOfWork.ProductCategories.GetByIdAsync(id);

            if (category == null)
            {
                return(NotFound(id));
            }

            category = _mapper.Map(model, category);
            _unitOfWork.ProductCategories.Put(category);
            category.DateModified = DateTime.UtcNow;
            _unitOfWork.SaveChanges();
            return(Ok(_mapper.Map <ProductCategoryViewModel>(category)));
        }