Exemple #1
0
        /*
         * Create new Category
         */
        public async Task <CreatedCategoryVM> CreateCategoryAsync(ReqCreateCategory reqData)
        {
            try
            {
                CreatedCategoryVM createdCategoryVM = new CreatedCategoryVM();
                // Created Category
                Logger.LogInformation("Create new category");
                string SlugName = StringHelper.GenerateSlug(reqData.Name);
                reqData.Slug     = SlugName;
                reqData.ParentId = reqData.ParentId ?? Guid.Empty;

                Guid     newId        = new Guid();
                Category categoryData = new Category
                {
                    Id       = newId,
                    Name     = reqData.Name,
                    ParentId = reqData.ParentId,
                    Slug     = reqData.Slug,
                    Seo      = new Seo
                    {
                        SeoTitle       = reqData.SeoTitle,
                        SeoKeys        = reqData.SeoKeys,
                        SeoDescription = reqData.SeoDescription,
                        ObjectId       = newId
                    }
                };
                Task <bool> categoryCreated = _uow.GetRepository <Category>().AddAsync(categoryData);
                _uow.SaveChanges();

                createdCategoryVM.categoryData = categoryData;
                return(await Task.FromResult(createdCategoryVM));
            }
            catch (Exception ex)
            {
                Logger.LogError(ex.Message.ToString());
                throw ex;
            }
        }
Exemple #2
0
        public async Task <ActionResult> CreateCategoryAsync([FromBody] ReqCreateCategory category)
        {
            var result = await _categoryLogic.CreateCategoryAsync(category);

            return(Ok(new BaseResponse(result)));
        }