Exemplo n.º 1
0
        public async Task <IActionResult> AddCategory(RequstModels.Category rCategory)
        {
            var sCategory = new DbModels.Category {
                Id          = Guid.NewGuid(),
                Title       = rCategory.Title,
                Description = rCategory.Description,
                RequestFrom = rCategory.RequestFrom,
                CreatedBy   = "system", // get user from token
                CreatedAt   = DateTime.UtcNow,
                ModifiedBy  = "system", // get user from token
                ModifiedAt  = DateTime.UtcNow
            };

            _categoryRepository.Add(sCategory);
            var isAdded = await _categoryRepository.Commit();

            if (isAdded)
            {
                return(Ok(new ViewModels.Category
                {
                    Id = sCategory.Id.ToString(),
                    Title = sCategory.Title,
                    Description = sCategory.Description
                }));
            }
            else
            {
                return(BadRequest());
            }
        }
Exemplo n.º 2
0
        public async Task <IActionResult> UpdateCategory(RequstModels.Category rCategory)
        {
            var sCategory = await _categoryRepository.Get(Guid.Parse(rCategory.Id));

            sCategory.Title       = rCategory.Title;
            sCategory.Description = rCategory.Description;
            sCategory.ModifiedAt  = DateTime.Now;
            sCategory.ModifiedBy  = "system";// get user from token

            var isModified = await _categoryRepository.Commit();

            if (isModified)
            {
                return(Ok(new ViewModels.Category
                {
                    Id = sCategory.Id.ToString(),
                    Title = sCategory.Title,
                    Description = sCategory.Description
                }));
            }
            else
            {
                return(BadRequest());
            }
        }