예제 #1
0
        public async Task <IActionResult> Index()
        {
            // With local context
            await unitOfWork.Run(async (r, context) =>
            {
                r.ConvertContextOfRepository(categoryRepository).ToUse(context);
                var categoriesWithLocalContext = await categoryRepository.GetCategories();
            });

            // Without local context
            var categories    = (await categoryRepository.GetCategories()).ToList();
            var subcategories = categories[0].Subcategories.Value;

            AddNotification(ViewNotification.Make("Alert sukses terbentuk", ViewNotification.SUCCESS));
            AddNotification(ViewNotification.Make("Alert Error terbentuk", ViewNotification.ERROR));
            return(View());
        }
예제 #2
0
        public async Task <IActionResult> Login(IndexViewModel viewModels)
        {
            if (!ModelState.IsValid)
            {
                return(View("Index", viewModels));
            }

            User user = await userService.Login(new User
            {
                UserEmail    = viewModels.UserEmail,
                UserPassword = viewModels.UserPassword
            });

            if (user == null)
            {
                AddNotification(ViewNotification.Make("User Tidak Ditemukan", ViewNotification.ERROR));
                return(View("Index", viewModels));
            }

            return(RedirectToAction("Index", "Home"));
        }
예제 #3
0
        public IActionResult Save(IndexViewModel indexViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View("Index", indexViewModel));
            }

            try
            {
                if (indexViewModel.SubCategoryId == 0)
                {
                    // Insert
                    ExecuteResult insertResult = subCategoryService.InsertSubCategory(new InsertSubCategory
                    {
                        CategoryId      = indexViewModel.CategoryId,
                        SubCategoryName = indexViewModel.SubCategoryName
                    });
                    AddNotification(ViewNotification.Make("Insert Success", "Success"));
                }
                else
                {
                    // Update
                    ExecuteResult updateResult = subCategoryService.UpdateSubCategory(new UpdateSubCategory
                    {
                        SubCategoryId   = indexViewModel.SubCategoryId,
                        CategoryId      = indexViewModel.CategoryId,
                        SubCategoryName = indexViewModel.SubCategoryName
                    });
                    AddNotification(ViewNotification.Make("Update Success", ViewNotification.SUCCESS));
                }
            }
            catch (Exception e)
            {
                AddNotification(ViewNotification.Make("Error", ViewNotification.ERROR));
                return(View("Index", indexViewModel));
            }

            return(RedirectToAction("Index", "SubCategory"));
        }
예제 #4
0
 public IActionResult SubCategoryTableViewComponentOnSearch(SubCategoriesTableViewModel subCategoriesTableViewModel)
 {
     AddNotification(ViewNotification.Make("Success Search", ViewNotification.SUCCESS));
     return(ViewComponent("SubCategoryTable", subCategoriesTableViewModel.CategoryId));
 }