Esempio n. 1
0
        public ActionResult SaveCategory(AddCategory model)
        {
            int id = (int)Session["admin"];

            ModelState.Remove("cId");
            if (!ModelState.IsValid)
            {
                return(View("AddCategory", model));
            }
            var categoryInDb = _context.GetCategory(model.cId);

            if (categoryInDb == null)
            {
                NoteCategory category = new NoteCategory
                {
                    Name         = model.CategoryName,
                    Description  = model.Description,
                    CreatedDate  = DateTime.Now,
                    CreatedBy    = id,
                    ModifiedDate = DateTime.Now,
                    ModifiedBy   = id,
                    IsActive     = true
                };
                _context.AddCategory(category);
                return(RedirectToAction("ManageCategory", "Admin"));
            }
            else
            {
                categoryInDb.Name         = model.CategoryName;
                categoryInDb.Description  = model.Description;
                categoryInDb.ModifiedDate = DateTime.Now;
                categoryInDb.ModifiedBy   = id;
                categoryInDb.IsActive     = true;
                _context.UpdateUp();
                return(RedirectToAction("ManageCategory", "Admin"));
            }
        }