Ejemplo n.º 1
0
        public async Task <IActionResult> AddOrEditCategory(long CategoryId, [Bind("CategoryId,CategoryName,ParentCategoryId,Remarks,categoryAction")] BeSafeModels.Category category)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    if (CategoryId == 0)
                    {
                        var CategoryEntity = mapCategoryModelToEntity.ConvertObject(category);
                        await categoryBusinessLogic.AddCategory(CategoryEntity);
                    }
                    else
                    {
                        switch (category.categoryAction.SetEmptyIfNull().ToUpper())
                        {
                        case "ADD":
                            BeSafeEntities.Category NewCategory = new BeSafeEntities.Category();
                            NewCategory.CategoryName     = category.CategoryName;
                            NewCategory.ParentCategoryId = CategoryId;
                            NewCategory.Remarks          = category.Remarks;
                            await categoryBusinessLogic.AddCategory(NewCategory);

                            break;

                        case "EDIT":
                        default:
                            var CategoryEntity = await categoryBusinessLogic.GetCategoryById(CategoryId);

                            CategoryEntity.CategoryName = category.CategoryName;
                            CategoryEntity.Remarks      = category.Remarks;
                            //var CategoryEntity = mapCategoryModelToEntity.ConvertObject(category);
                            await categoryBusinessLogic.UpdateCategory(CategoryEntity);

                            break;
                        }
                    }
                }
                catch (Exception)
                {
                    throw;
                }

                var categories    = categoryBusinessLogic.GetAllCategories().Result;
                var categoryModel = mapCategoryEntityToModel.ConvertObjectCollection(categories);
                return(Json(new { isValid = true, html = Helper.RenderRazorViewToString(this, "_ViewAllCategory", categoryModel) }));
            }
            return(Json(new { isValid = false, html = Helper.RenderRazorViewToString(this, "AddOrEditCategory", category) }));
        }
Ejemplo n.º 2
0
        public async Task <Entities.Category> UpdateCategory(Entities.Category category)
        {
            await this._categoryRepository.UpdateAsync(category, true);

            return(category);
        }
Ejemplo n.º 3
0
 public async Task DeleteCategory(Entities.Category category)
 {
     await this._categoryRepository.DeleteAsync(category, true);
 }
Ejemplo n.º 4
0
        public async Task <Entities.Category> AddCategory(Entities.Category category)
        {
            var result = await this._categoryRepository.InsertAsync(category, true);

            return(category);
        }