//[AuthorizeUser(RoleModule.SubCategory, Function.View)]
        public JsonResult GetSubCategories(SubcategoryViewModel dViewModel)
        {
            PaginationInfo pager = new PaginationInfo();

            pager = dViewModel.Pager;

            PaginationViewModel pViewModel = new PaginationViewModel();

            try
            {
                pViewModel.dt = _subcatManager.GetSubcategories(dViewModel.SubcategoryInfo.CategoryId, dViewModel.SubcategoryInfo.SubCategoryName, ref pager);

                pViewModel.Pager = pager;

                Logger.Debug("Subcategory Controller GetSubCategories");
            }

            catch (Exception ex)
            {
                dViewModel.FriendlyMessage.Add(MessageStore.Get("SYS01"));

                Logger.Error("Subcategory Controller - GetSubCategories" + ex.ToString());
            }

            return(Json(JsonConvert.SerializeObject(pViewModel), JsonRequestBehavior.AllowGet));
        }
        //[AuthorizeUser(RoleModule.SubCategory, Function.Create)]
        public JsonResult Insert(SubcategoryViewModel dViewModel)
        {
            Set_Date_Session(dViewModel.SubcategoryInfo);
            using (TransactionScope tran = new TransactionScope())
            {
                try
                {
                    dViewModel.SubcategoryInfo.Id = _subcatManager.Insert_Subcategory(dViewModel.SubcategoryInfo);

                    dViewModel.FriendlyMessage.Add(MessageStore.Get("SUBCATEGORY01"));

                    tran.Complete();

                    Logger.Debug("Sub Category Controller : Insert Success");
                }
                catch (Exception ex)
                {
                    tran.Dispose();

                    dViewModel.FriendlyMessage.Add(MessageStore.Get("SYS01"));

                    Logger.Debug("Sub Category Controller : Insert Error " + ex.Message);
                }
            }
            return(Json(dViewModel));
        }
        //[AuthorizeUser(RoleModule.SubCategory, Function.Edit)]
        public JsonResult Update(SubcategoryViewModel dViewModel)
        {
            Set_Date_Session(dViewModel.SubcategoryInfo);
            using (TransactionScope tran = new TransactionScope())
            {
                try
                {
                    _subcatManager.Update_Subcategory(dViewModel.SubcategoryInfo);

                    dViewModel.FriendlyMessage.Add(MessageStore.Get("SUBCATEGORY02"));

                    tran.Complete();

                    Logger.Debug("Subcategory Controller Update");
                }
                catch (Exception ex)
                {
                    tran.Dispose();
                    dViewModel.FriendlyMessage.Add(MessageStore.Get("SYS01"));

                    Logger.Error("Subcategory Controller - Update  " + ex.Message);
                }
            }
            return(Json(dViewModel));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Create(SubcategoryViewModel model)
        {
            if (ModelState.IsValid)
            {
                var doesSubCategoryExists = _db.Subcategory.Include(s => s.Category).Where(s => s.Name == model.subcategory.Name && s.Category.Id == model.subcategory.CategoryId);

                if (doesSubCategoryExists.Count() > 0)
                {
                    StatusMessage = "Error - Subcategory already exists." + doesSubCategoryExists.First().Name;
                }
                else
                {
                    _db.Subcategory.Add(model.subcategory);
                    await _db.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
            }

            SubcategoryViewModel modelVM = new SubcategoryViewModel()
            {
                CategoryList    = await _db.Category.ToListAsync(),
                subcategory     = model.subcategory,
                subcategoryList = await _db.Subcategory.OrderBy(p => p.Name).Select(p => p.Name).ToListAsync(),
                StatusMessage   = StatusMessage
            };

            return(View(modelVM));
        }
Exemplo n.º 5
0
        public static Subcategory ToViewModel(this SubcategoryViewModel subcategoryViewModel)
        {
            var subcategory = new Subcategory
            {
                Id   = subcategoryViewModel.Id,
                Name = subcategoryViewModel.Name
            };

            return(subcategory);
        }
Exemplo n.º 6
0
 public IEnumerable<SubcategoryViewModel> GetAll()
 {
     List<SubcategoryViewModel> subcatViewModels = new List<SubcategoryViewModel>();
     foreach (Subcategory subcategory in _subcategoriesRepository.GetAll())
     {
         SubcategoryViewModel subcategoryViewModel = MapToViewModel(subcategory);
         subcatViewModels.Add(subcategoryViewModel);
     }
     return subcatViewModels;
 }
        public ActionResult Create()
        {
            var viewModel = new SubcategoryViewModel
            {
                Subcategory = new Subcategory(),
                Categories  = _context.Categories.ToList()
            };

            return(View("SubcategoryForm", viewModel));
        }
        // GET: /Category/{mainName}/{subcategoryName}/{subcategoryId}
        public ViewResult Details(int id, string sortOrder, bool descending = false)
        {
            if (!string.IsNullOrEmpty(sortOrder))
            {
                SaveSortingState(sortOrder, descending);
            }
            Subcategory          subcategory = _subcategoryRepository.GetById(id);
            SubcategoryViewModel model       = Mapper.Map <SubcategoryViewModel>(subcategory);

            return(View(model));
        }
Exemplo n.º 9
0
        public override void Setup()
        {
            base.Setup();
            _model = new SubcategoryViewModel();
            _subcategoryRepository = new Mock <IRepository <Subcategory> >();

            _controller = new SubcategoryController(
                _subcategoryRepository.Object,
                _mapper.Object
                );
        }
Exemplo n.º 10
0
        public SubcategoryViewModel GetSubcategoryById(int subcategoryId)
        {
            Subcategory          subcategory          = _ctx.Subcategories.Include(x => x.SubcategoryAttributes).FirstOrDefault(f => f.Id == subcategoryId);
            SubcategoryViewModel subcategoryViewModel = _subcategoryFactory.SubcategoryToViewModel(subcategory);

            Category category = _ctx.Categories.FirstOrDefault(f => f.Id == subcategory.CategoryId);

            subcategoryViewModel.CategoryName = category.Name;

            return(subcategoryViewModel);
        }
Exemplo n.º 11
0
        //Get Action for Create
        public IActionResult create()
        {
            SubcategoryViewModel model = new SubcategoryViewModel()
            {
                subCategory     = new Models.Subcategory(),
                categorieslist  = db.categories.ToList(),
                subcategorylist = db.subcategory.OrderBy(p => p.name).Select(x => x.name).Distinct().ToList()
            };

            return(View(model));
        }
Exemplo n.º 12
0
        public static SubcategoryViewModel ToViewModel(this Subcategory subcategory)
        {
            var subcategoryViewModel = new SubcategoryViewModel
            {
                Id           = subcategory.Id,
                Name         = subcategory.Name.Trim(),
                CategoryName = subcategory.Category?.Name.Trim()
            };

            return(subcategoryViewModel);
        }
        // GET
        public async Task <IActionResult> Index()
        {
            var subcategories = await _subcategoryRepository.getAll();

            var subcategoryviewmodel = new SubcategoryViewModel()
            {
                Subcategories = subcategories.ToList()
            };

            return(View(subcategoryviewmodel));
        }
Exemplo n.º 14
0
        // GET CREATE
        public async Task <IActionResult> Create()
        {
            SubcategoryViewModel model = new SubcategoryViewModel()
            {
                CategoryList    = await _db.Category.ToListAsync(),
                subcategory     = new Models.Subcategory(),
                subcategoryList = await _db.Subcategory.OrderBy(p => p.Name).Select(p => p.Name).Distinct().ToListAsync()
            };

            return(View(model));
        }
Exemplo n.º 15
0
        public ActionResult New()

        {
            var vm = new SubcategoryViewModel
            {
                DepartmentList = db.Categories.ToList(),
                CategoryList   = db.Subcategories.ToList()
            };

            return(View(vm));
        }
Exemplo n.º 16
0
 public ActionResult Create([Bind(Include = "SubcategoryID,Name,UI,Image")] SubcategoryViewModel subcategory, int catid)
 {
     if (ModelState.IsValid)
     {
         subcategory.CategoryID = catid;
         _subcategoryService.Add(subcategory);
         return(RedirectToAction("Index", "SubcategoryProperty", new { id = subcategory.SubcategoryID }));
     }
     ViewBag.CategoryID = new SelectList(_categoryService.GetAll(), "CategoryID", "Name", subcategory.CategoryID);
     return(View(subcategory));
 }
Exemplo n.º 17
0
 public ActionResult Edit([Bind(Include = "SubcategoryID,Name,CategoryID,UI,Image")] SubcategoryViewModel subcategory, int?imgId, int catId)
 {
     if (ModelState.IsValid)
     {
         subcategory.ImageID    = imgId;
         subcategory.CategoryID = catId;
         _subcategoryService.Edit(subcategory);
         return(RedirectToAction("IndexAdmin", new { id = subcategory.CategoryID }));
     }
     ViewBag.CategoryID = new SelectList(_categoryService.GetAll(), "CategoryID", "Name", subcategory.CategoryID);
     return(View(subcategory));
 }
Exemplo n.º 18
0
        // GET: Subcategory
        public ActionResult Index()
        {
            var subcategoryList = new SubcategoryViewModel();

            {
                subcategoryList.Subcategory = db.Subcategories.ToList();
            }
            if (subcategoryList == null)
            {
                return(HttpNotFound());
            }
            return(View(subcategoryList));
        }
Exemplo n.º 19
0
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            SubcategoryViewModel subcategory = _subcategoryService.GetById((int)id);

            if (subcategory == null)
            {
                return(HttpNotFound());
            }
            return(View(subcategory));
        }
Exemplo n.º 20
0
 public ActionResult CreateSUBCATEGORY(SubcategoryViewModel ee)
 {
     try
     {
         if (ModelState.IsValid)
         {
             sub.Create(mapper.Map <SubcategoryViewModel, Subcategory>(ee));
         }
     }
     catch
     {
         ModelState.AddModelError("", "Unable to save changes. ");
     }
     return(Ok());
 }
Exemplo n.º 21
0
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            SubcategoryViewModel subcategory = _subcategoryService.GetById((int)id);

            if (subcategory == null)
            {
                return(HttpNotFound());
            }
            ViewBag.CategoryID = new SelectList(_categoryService.GetAll(), "CategoryID", "Name", subcategory.CategoryID);
            return(View(subcategory));
        }
Exemplo n.º 22
0
        public ActionResult Save(Subcategory subcategory)
        {
            if (subcategory.SubcategoryId == 0)
            {
                if (ModelState.IsValid)
                {
                    subcategory.CreatedDate = DateTime.Now;
                    db.Subcategories.Add(subcategory);
                    db.SaveChanges();
                }
                else
                {
                    var vm = new SubcategoryViewModel
                    {
                        SubCategory    = subcategory,
                        DepartmentList = db.Categories.ToList(),
                        CategoryList   = db.Subcategories.ToList()
                    };
                    return(View("New", vm));
                }
            }
            else
            {
                if (ModelState.IsValid)
                {
                    var dbsubcategory = db.Subcategories.Single(s => s.SubcategoryId == subcategory.SubcategoryId);
                    dbsubcategory.Name         = subcategory.Name;
                    dbsubcategory.ModifiedDate = DateTime.Now;
                    dbsubcategory.Pic          = subcategory.Pic;
                    dbsubcategory.ParentId     = subcategory.ParentId;
                    dbsubcategory.Description  = subcategory.Description;
                    dbsubcategory.CategoryId   = subcategory.CategoryId;

                    db.SaveChanges();
                }
                else
                {
                    var vm = new SubcategoryViewModel
                    {
                        SubCategory    = subcategory,
                        DepartmentList = db.Categories.ToList(),
                        CategoryList   = db.Subcategories.ToList()
                    };
                    return(View("Edit", vm));
                }
            }
            return(RedirectToAction("Index", "SubCategory"));
        }
Exemplo n.º 23
0
        public ActionResult Edit(int id)
        {
            TempData.Remove("ProductAlert");
            TempData.Remove("SubcategoryAlert");

            var subcategory = db.Subcategories.Single(s => s.SubcategoryId == id);
            var vm          = new SubcategoryViewModel
            {
                SubCategory    = subcategory,
                DepartmentList = db.Categories.ToList(),
                CategoryList   = db.Subcategories.
                                 ToList()
            };

            return(View(vm));
        }
Exemplo n.º 24
0
        public HttpResponseMessage Manage(int?id)
        {
            Subcategory p = null;

            if (id != null)
            {
                p = Uow.PartModel.Get((int)id);
            }
            var brands = Uow.Brand.GetAll();
            SubcategoryViewModel vm = new SubcategoryViewModel {
                PartModel = p, Categories = brands.ToList()
            };

            Uow.Dispose();
            return(Request.CreateResponse(HttpStatusCode.OK, vm));
        }
        public IActionResult Index(Guid id)
        {
            var subcategory = _subcategoryRepository.GetSubcategory(id);
            var creatures   = _creatureRepository.GetCreaturesBySubcategory(subcategory);

            var vm = new SubcategoryViewModel()
            {
                Id             = subcategory.Id,
                CommonName     = subcategory.CommonName,
                ScientificName = subcategory.ScientificName,
                Description    = subcategory.Description,
                Creatures      = Mapper.Map <IEnumerable <Creature>, IList <CreatureViewModel> >(creatures),
            };

            return(View(vm));
        }
Exemplo n.º 26
0
        // GET: /Category/{mainName}/{subcategoryName}/{subcategoryId}
        public ViewResult Details(int id, string sortOrder, bool descending = false)
        {
            if (!string.IsNullOrEmpty(sortOrder))
            {
                SaveSortingState(sortOrder, descending);
            }
            Subcategory          subcategory = _subcategoryRepository.GetById(id);
            SubcategoryViewModel model       = _mapper.Map <SubcategoryViewModel>(subcategory);

            if (model == null)
            {
                return(View("_Error", new string[] { ErrorMessage.ItemNotFound }));
            }

            return(View(model));
        }
        public IHttpActionResult GetSubcategoryViewModel(int?subcategoryid)
        {
            Subcategory subcategory = null;

            if (subcategoryid != null)
            {
                subcategory = db.Subcategories.SingleOrDefault(s => s.SubcategoryId == subcategoryid);
            }
            var svm = new SubcategoryViewModel()
            {
                SubCategory    = subcategory,
                DepartmentList = db.Categories.ToList(),
                CategoryList   = db.Subcategories.ToList()
            };

            return(Ok(svm));
        }
        public async Task <IActionResult> Add()
        {
            int             langId    = HttpContext.GetLanguage("adminLangId");
            List <Language> languages = await db.Languages.ToListAsync();

            List <CategoryLanguage> categoryLanguages = await db.CategoryLanguages.Where(cl => cl.LanguageId == langId)
                                                        .Include(cl => cl.Category)
                                                        .Include(cl => cl.Language)
                                                        .ToListAsync();

            SubcategoryViewModel model = new SubcategoryViewModel()
            {
                Languages         = languages,
                categoryLanguages = categoryLanguages
            };

            return(View(model));
        }
        public async Task <IActionResult> Index()
        {
            SubcategoryViewModel model = new SubcategoryViewModel();

            Checker.CheckLangId(HttpContext, db, "adminLangId").Wait();
            HttpContext.SetCurrentPage("index", "subcategory");
            int langId = HttpContext.GetLanguage("adminLangId");

            model.subcategoryLanguages = await db.SubcategoryLanguages.Where(sl => sl.LanguageId == langId)
                                         .Include(sl => sl.Subcategory)
                                         .ToListAsync();

            model.categoryLanguages = await db.CategoryLanguages.Where(cl => cl.LanguageId == langId)
                                      .Include(cl => cl.Category)
                                      .ToListAsync();

            return(View(model));
        }
        public ActionResult Manage(int?id)
        {
            ViewBag.Mode = "Create";
            Subcategory p = null;

            if (id != null)
            {
                ViewBag.Mode = "Edit";
                p            = Uow.PartModel.Get((int)id);
            }
            var brands = Uow.Brand.GetAll();
            SubcategoryViewModel vm = new SubcategoryViewModel {
                PartModel = p, Categories = brands.ToList()
            };

            Uow.Dispose();
            return(View("Manage", vm));
        }