public ActionResult AddType(int?ID)
 {
     if (Session["ID"] != null)
     {
         int  id         = Convert.ToInt32(Session["ID"]);
         int  RoleMember = Convert.ToInt32(Enums.UserRoleId.Member);
         User user       = db.Users.Where(x => x.ID == id).FirstOrDefault();
         if (user.RoleID != RoleMember)
         {
             ManageTypeViewModel Model = new ManageTypeViewModel();
             if (ID != null)
             {
                 NoteType countryData = db.NoteTypes.Where(x => x.ID == ID).FirstOrDefault();
                 Model.Type        = countryData.Name;
                 Model.Description = countryData.Description;
                 return(View(Model));
             }
             return(View());
         }
         else
         {
             return(RedirectToAction("Index", "Home"));
         }
     }
     else
     {
         return(RedirectToAction("Login", "Account"));
     }
 }
 public ActionResult AddType(ManageTypeViewModel model)
 {
     if (ModelState.IsValid)
     {
         NoteType countryData = db.NoteTypes.Where(x => x.Name.Equals(model.Type)).FirstOrDefault();
         int      AddedBy     = Convert.ToInt32(Session["ID"]);
         if (countryData != null)
         {
             countryData.Name         = model.Type;
             countryData.Description  = model.Description;
             countryData.ModifiedDate = DateTime.Now;
             countryData.ModifiedBy   = AddedBy;
             countryData.IsActive     = true;
             db.SaveChanges();
         }
         else
         {
             NoteType NewEntry = new NoteType()
             {
                 Name        = model.Type,
                 Description = model.Description,
                 CreatedBy   = AddedBy,
                 CreatedDate = DateTime.Now,
                 IsActive    = true,
             };
             db.NoteTypes.Add(NewEntry);
             db.SaveChanges();
         }
         return(RedirectToAction("ManageType", "Type"));
     }
     else
     {
         return(View(model));
     }
 }
        public ActionResult EditType(int id)
        {
            ViewBag.Settings   = "active";
            ViewBag.managetype = "active";

            var user   = db.Users.FirstOrDefault(x => x.Email == User.Identity.Name);
            var detail = db.NoteTypes.FirstOrDefault(x => x.ID == id);

            ManageTypeViewModel typeModel = new ManageTypeViewModel();

            typeModel.ID          = detail.ID;
            typeModel.typeName    = detail.Name;
            typeModel.description = detail.Description;

            return(View(typeModel));
        }
        public ActionResult EditType(ManageTypeViewModel typModel)
        {
            var user  = db.Users.FirstOrDefault(x => x.Email == User.Identity.Name);
            var model = db.NoteTypes.Where(x => x.ID == typModel.ID).FirstOrDefault();

            if (ModelState.IsValid)
            {
                model.Name         = typModel.typeName;
                model.Description  = typModel.description;
                model.ModifiedDate = DateTime.Now;
                model.ModifiedBy   = user.ID;
                model.IsActive     = true;

                db.SaveChanges();

                return(RedirectToAction("ManageType"));
            }

            return(View());
        }
 public ActionResult ManageType()
 {
     if (Session["ID"] != null)
     {
         int  id         = Convert.ToInt32(Session["ID"]);
         int  RoleMember = Convert.ToInt32(Enums.UserRoleId.Member);
         User user       = db.Users.Where(x => x.ID == id).FirstOrDefault();
         if (user.RoleID != RoleMember)
         {
             ManageTypeViewModel Model = new ManageTypeViewModel();
             Model.getNoteTypeData_Results = db.GetNoteTypeData().ToList();
             return(View(Model));
         }
         else
         {
             return(RedirectToAction("Index", "Home"));
         }
     }
     else
     {
         return(RedirectToAction("Login", "Account"));
     }
 }
        public ActionResult AddType(ManageTypeViewModel type)
        {
            var user = db.Users.FirstOrDefault(x => x.Email == User.Identity.Name);

            if (ModelState.IsValid)
            {
                //add data to notetype table
                NoteTypes Types = new NoteTypes();

                Types.Name        = type.typeName;
                Types.Description = type.description;
                Types.CreatedDate = DateTime.Now;
                Types.CreatedBy   = user.ID;
                Types.IsActive    = true;

                db.NoteTypes.Add(Types);
                db.SaveChanges();

                return(RedirectToAction("ManageType"));
            }

            return(View());
        }
        public ActionResult ManageType(string SortOrder, string Type_search, int Type_page = 1)
        {
            ViewBag.Settings   = "active";
            ViewBag.managetype = "active";

            //sortorder
            ViewBag.TypeSortParm        = SortOrder == "Type" ? "Type_desc" : "Type";
            ViewBag.DescriptionSortParm = SortOrder == "Description" ? "Description_desc" : "Description";
            ViewBag.AddedBySortParm     = SortOrder == "AddedBy" ? "AddedBy_desc" : "AddedBy";
            ViewBag.ActiveSortParm      = SortOrder == "Active" ? "Active_desc" : "Active";
            ViewBag.DateSortParm        = SortOrder == "Date" ? "Date_desc" : "Date";

            ManageTypeViewModel Types = new ManageTypeViewModel();

            //Query string
            var type = from typ in db.NoteTypes
                       join ur in db.Users on typ.CreatedBy equals ur.ID
                       select new ManageType {
                Type = typ, users = ur
            };

            //searching
            if (Type_search != null)
            {
                type = type.Where(x => x.Type.Name.Contains(Type_search) ||
                                  x.Type.Description.Contains(Type_search) ||
                                  x.Type.CreatedDate.ToString().Contains(Type_search) ||
                                  x.users.FirstName.Contains(Type_search) ||
                                  x.users.LastName.Contains(Type_search));
            }

            //sorting
            switch (SortOrder)
            {
            case "Type_desc":
                type = type.OrderByDescending(s => s.Type.Name);
                break;

            case "Type":
                type = type.OrderBy(s => s.Type.Name);
                break;

            case "Description_desc":
                type = type.OrderByDescending(s => s.Type.Description);
                break;

            case "Description":
                type = type.OrderBy(s => s.Type.Description);
                break;

            case "AddedBy_desc":
                type = type.OrderByDescending(s => s.users.FirstName);
                break;

            case "AddedBy":
                type = type.OrderBy(s => s.users.FirstName);
                break;

            case "Active_desc":
                type = type.OrderByDescending(s => s.Type.IsActive);
                break;

            case "Active":
                type = type.OrderBy(s => s.Type.IsActive);
                break;

            case "Date_desc":
                type = type.OrderByDescending(s => s.Type.CreatedDate);
                break;

            case "Date":
                type = type.OrderBy(s => s.Type.CreatedDate);
                break;

            default:
                type = type.OrderByDescending(s => s.Type.CreatedDate);
                break;
            }

            //assign data to model
            Types.NoteTypes = type;

            //pagination
            var pager = new Pager(type.Count(), Type_page, 10);

            ViewBag.currentPage = pager.CurrentPage;
            ViewBag.endPage     = pager.EndPage;
            ViewBag.startpage   = pager.StartPage;
            ViewBag.totalPage   = type.Count();

            Types.NoteTypes = type.Skip((pager.CurrentPage - 1) * pager.PageSize).Take(pager.PageSize);

            return(View(Types));
        }