コード例 #1
0
        //GET - INDEX
        public async Task <IActionResult> Index(int page = 1)
        {
            var subCategories = await _db.SubCategories.Include(s => s.Category).ToListAsync();

            PagingInfo paging = new PagingInfo
            {
                CurrentPage  = page,
                ItemsPerPage = SubCategoriesPerPgae,
                TotalItem    = subCategories.Count,
                UrlParam     = "/Admin/Subcategory?page=:"
            };

            SubCategoryVM subCategoriesVM = new SubCategoryVM()
            {
                SubCategories = subCategories,
                PagingInfo    = paging
            };

            // get and skip the subCategories depend on PageSelected and PageSize to display them
            subCategoriesVM.SubCategories = subCategoriesVM.SubCategories.OrderBy(p => p.Id)
                                            .Skip((page - 1) * SubCategoriesPerPgae) // to show next items
                                            .Take(SubCategoriesPerPgae).ToList();

            return(View(subCategoriesVM));
        }
コード例 #2
0
        public IActionResult Upsert(int?id)
        {
            IEnumerable <Category> Categories = _unitOfWork.Category.GetAll();

            SubCategoryVM subCategoryVM = new SubCategoryVM()
            {
                SubCategory  = new SubCategory(),
                CategoryList = Categories.Select(i => new SelectListItem
                {
                    Text  = i.Name,
                    Value = i.Id.ToString()
                })
            };

            if (id == null)
            {
                return(View(subCategoryVM));
            }

            subCategoryVM.SubCategory = _unitOfWork.SubCategory.Get(id.GetValueOrDefault());
            if (subCategoryVM.SubCategory == null)
            {
                return(NotFound());
            }
            return(View(subCategoryVM));
        }
コード例 #3
0
        public async Task <string> AddUpdateUser(SubCategoryVM subCategoryVM)
        {
            SubCategoryDomainModel subCategoryDM = new SubCategoryDomainModel();

            AutoMapper.Mapper.Map(subCategoryVM, subCategoryDM);
            return(await subCategoryBusiness.AddUpdateSubCategory(subCategoryDM));
        }
コード例 #4
0
        public IActionResult InsertSubCategory(SubCategoryVM subCategoryVM)
        {
            User        currentAdmin = HttpContext.Session.Get <User>("currentUser");
            SubCategory subCategory  = new SubCategory();

            if (ModelState.IsValid)
            {
                subCategory.CategoryName = subCategoryVM.SubCategoryName;
                subCategory.Description  = subCategoryVM.Overview;
                subCategory.CategoryID   = subCategoryVM.CatID;
                if (subCategory != null)
                {
                    try
                    {
                        subCategoryBLL.Add(subCategory);
                        this._logger.LogInformation($"AdminID : {currentAdmin.ID} is inserted the SubCategoryID : {subCategory.ID}.");
                    }
                    catch (Exception)
                    {
                        throw;
                    }
                }
            }
            return(View("Index"));
        }
コード例 #5
0
        public ActionResult Update(Guid id)//Bilgisayar
        {
            SubCategoryVM model = new SubCategoryVM();

            model.SubCategory = sub.GetById(id);
            model.Categories  = category.GetActive();
            return(View(model));
        }
コード例 #6
0
        public IActionResult Create()
        {
            SubCategoryVM = new SubCategoryVM()
            {
                SubCategory  = new SubCategory(),
                CategoryList = _unitOfWork.Category.GetCategoryListForDropDown()
            };

            return(View(SubCategoryVM));
        }
コード例 #7
0
 public IActionResult Create(SubCategoryVM subCategoryVM)
 {
     if (ModelState.IsValid)
     {
         _unitOfWork.SubCategory.Add(subCategoryVM.SubCategory);
         _unitOfWork.Save();
         return(RedirectToAction("Index"));
     }
     return(View(subCategoryVM));
 }
コード例 #8
0
        public IActionResult Edit(SubCategoryVM subCategoryVM)
        {
            if (ModelState.IsValid)
            {
                _unitOfWork.SubCategory.Update(subCategoryVM.SubCategory);
                _unitOfWork.Save();
            }

            return(RedirectToAction(nameof(Index)));
        }
コード例 #9
0
        public IActionResult Details(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            SubCategoryVM = new SubCategoryVM();

            SubCategoryVM.SubCategory = _unitOfWork.SubCategory.Get(id.GetValueOrDefault());
            SubCategoryVM.Category    = _unitOfWork.Category.GetFirstOrDefault(c => c.Id == SubCategoryVM.SubCategory.CategoryId);

            return(View(SubCategoryVM));
        }
コード例 #10
0
        public ActionResult Update(Guid id)
        {
            SubCategory   sub   = _subCategoryService.GetById(id);
            SubCategoryVM model = new SubCategoryVM();

            model.SubCategory.ID          = sub.ID;
            model.SubCategory.Name        = sub.Name;
            model.SubCategory.Description = sub.Description;
            List <Category> categorymodel = _categoryService.GetActive();

            model.Categories = categorymodel;

            return(View(model));
        }
コード例 #11
0
        public PartialViewResult DetailsSubCategory(long id)
        {
            var           data = SubCategroyDAL.GetOne(id);
            SubCategoryVM obj  = new SubCategoryVM()
            {
                ID           = data.ID,
                Name         = data.Name,
                CreatedBy    = data.CreatedBy,
                CreationDate = data.CreationDate,
                UpdatedBy    = data.UpdatedBy,
                UpdatedDate  = data.UpdatedDate
            };

            ViewBag.FormName = "DetailsSubCategory";
            return(PartialView("AddSubCategory", obj));
        }
コード例 #12
0
        public IActionResult Edit(int?id)
        {
            SubCategoryVM = new SubCategoryVM()
            {
                SubCategory  = new SubCategory(),
                CategoryList = _unitOfWork.Category.GetCategoryListForDropDown()
            };

            if (id != null)
            {
                SubCategoryVM.SubCategory = _unitOfWork.SubCategory.Get(id.GetValueOrDefault());
            }


            return(View(SubCategoryVM));
        }
コード例 #13
0
 public IActionResult Upsert(SubCategoryVM subcategoryVM)
 {
     if (ModelState.IsValid)
     {
         if (subcategoryVM.SubCategory.Id == 0)
         {
             _unitOfWork.SubCategory.Add(subcategoryVM.SubCategory);
         }
         else
         {
             _unitOfWork.SubCategory.Update(subcategoryVM.SubCategory);
         }
         _unitOfWork.Save();
         return(RedirectToAction(nameof(Index)));
     }
     return(View(subcategoryVM));
 }
コード例 #14
0
        //HttpGet sayfayı gösterecek
        public ActionResult Update(Guid id)
        {
            //Sayfaya 2 model gidecek . biri Kategori Listesi , biri güncellenecek verinin kendisidir.
            //Bu yüzden Admin Areasında viewModel class'ı açtık
            SubCategoryVM vm = new SubCategoryVM();

            vm.KatListesi = _categoryService.GetActive();

            //sayfayada güncellenecek veriyi önce veritabanından buluyoruz.
            SubCategory orjVeri = _subcategoryService.GetByID(id);

            vm.ID          = orjVeri.ID;
            vm.Name        = orjVeri.Name;
            vm.Description = orjVeri.Description;
            vm.CategoryID  = orjVeri.CategoryID;

            return(View(vm));
        }
コード例 #15
0
        public JsonResult PostSubCategory(SubCategoryVM vm)
        {
            string message = "";

            SubCategory subcategory = new SubCategory()
            {
                Name         = vm.Name,
                CategoryFK   = vm.CategoryFK,
                CreatedBy    = 1,
                CreationDate = DateTime.Now
            };

            if (SubCategroyDAL.Add(subcategory, out message))
            {
                return(Json(new { done = true, message }, JsonRequestBehavior.AllowGet));
            }
            return(Json(new { done = false, message }, JsonRequestBehavior.AllowGet));
        }
コード例 #16
0
        public JsonResult EditSubCategory(SubCategoryVM vm)
        {
            SubCategory sucategory = new SubCategory()
            {
                ID           = vm.ID,
                Name         = vm.Name,
                CreatedBy    = vm.CreatedBy,
                CreationDate = vm.CreationDate,
                UpdatedBy    = 1,
                UpdatedDate  = DateTime.Now
            };

            if (SubCategroyDAL.Edit(sucategory))
            {
                return(Json(new { done = true }, JsonRequestBehavior.AllowGet));
            }
            return(Json(new { done = false }, JsonRequestBehavior.AllowGet));
        }
コード例 #17
0
        SubCategoryVM GetSubCategoryVM(SubCategory subCategory = null)
        {
            SubCategoryVM subCategoryVM = new SubCategoryVM();

            foreach (Category item in categoryBLL.GetAll().Data)
            {
                subCategoryVM.Categories.Add(new SelectListItem
                {
                    Text  = item.CategoryName,
                    Value = item.ID.ToString()
                });
            }
            if (subCategory != null)
            {
                subCategoryVM.SubCategoryName = subCategory.CategoryName;
                subCategoryVM.Overview        = subCategory.Description;
                subCategoryVM.CatID           = subCategory.CategoryID;
            }
            return(subCategoryVM);
        }
コード例 #18
0
        //GET - INDEX
        public async Task <IActionResult> Index(int page = 1)
        {
            var subCategories = await _db.SubCategories.Include(s => s.Category).ToListAsync();

            PagingInfo paging = new PagingInfo
            {
                CurrentPage  = page,
                ItemsPerPage = SubCategoriesPerPgae,
                TotalItem    = subCategories.Count,
                UrlParam     = "/Admin/Subcategory?page=:"
            };

            SubCategoryVM subCategoriesVM = new SubCategoryVM()
            {
                SubCategories = subCategories,
                PagingInfo    = paging
            };

            subCategoriesVM.SubCategories = subCategoriesVM.SubCategories.OrderBy(p => p.Id)
                                            .Skip((page - 1) * SubCategoriesPerPgae)
                                            .Take(SubCategoriesPerPgae).ToList();

            return(View(subCategoriesVM));
        }
コード例 #19
0
 public SubCategoryPage(List <Category> subCategoryList, Ticket ticket)
 {
     InitializeComponent();
     BindingContext = new SubCategoryVM(Navigation, subCategoryList, ticket);
 }