예제 #1
0
        public async Task <IActionResult> CreateUpdateCategory(CmsCategoryCreateUpdateViewModel model)
        {
            if (model.Id != null)
            {
                var category = await _dbContext.ContentCategories.FindAsync(model.Id);

                if (category == null)
                {
                    throw new AwroNoreException("Category not found");
                }

                category.Title       = model.Title;
                category.Title_Ar    = model.Title_Ar;
                category.Title_Ku    = model.Title_Ku;
                category.LayoutStyle = model.LayoutStyle;
                category.UpdatedAt   = DateTime.Now;

                _dbContext.Entry(category).State = EntityState.Modified;
            }
            else
            {
                var category = _mapper.Map <ContentCategory>(model);

                await _dbContext.ContentCategories.AddAsync(category);
            }

            await _dbContext.SaveChangesAsync();

            return(Json(new { success = true, message = Messages.ActionDoneSuccesfully }));
        }
예제 #2
0
        public async Task <IActionResult> CreateUpdateCategory(int?id)
        {
            ViewBag.LayoutStyles = MyEnumExtensions.EnumToSelectList <ContentLayoutStyle>().ToList();

            var model = new CmsCategoryCreateUpdateViewModel
            {
                Id = id
            };

            if (id != null)
            {
                var category = await _dbContext.ContentCategories.FindAsync(id);

                if (category == null)
                {
                    throw new AwroNoreException("Category not found");
                }

                model = _mapper.Map <CmsCategoryCreateUpdateViewModel>(category);
            }

            return(PartialView(model));
        }