Example #1
0
 public ActionResult Edit(ProfileVM profileVM)
 {
     try
     {
         using (DMSDBContext dc = new DMSDBContext())
         {
             string message  = "";
             var    validate = dc.Departments.Where(a => a.DeptName == profileVM.DeptName).FirstOrDefault();
             if (validate == null)
             {
                 var data = dc.Departments.Where(x => x.DeptId == profileVM.DeptId).FirstOrDefault();
                 data.DeptName        = profileVM.DeptName;
                 data.DeptId          = profileVM.DeptId;
                 dc.Entry(data).State = EntityState.Modified;
                 dc.SaveChanges();
                 message             = "Department Edited Successfully";
                 TempData["Message"] = message;
                 return(RedirectToAction("Index", "Department"));
             }
             else
             {
                 message             = "This Department is already created. Please use another!!";
                 TempData["Message"] = message;
                 return(RedirectToAction("Create", "Department"));
             }
         }
     }
     catch
     {
         return(View());
     }
 }
Example #2
0
 public ActionResult Delete(int id, ProfileVM profileVM)
 {
     try
     {
         using (DMSDBContext dc = new DMSDBContext())
         {
             int    uid  = Convert.ToInt32(Session["id"]);
             var    data = dc.Documents.Where(x => x.DocumentId == id).FirstOrDefault();
             string strPhysicalFolder = Server.MapPath("//Documents/" + data.Category.CategoryName + "/");
             string strFileFullPath   = strPhysicalFolder + data.DocumentName;
             if (System.IO.File.Exists(strFileFullPath))
             {
                 System.IO.File.Delete(strFileFullPath);
                 dc.Documents.Remove(data);
                 dc.SaveChanges();
             }
             string message = "Document Deleted Successfully";
             TempData["Message"] = message;
             return(RedirectToAction("Index", "Document"));
         }
     }
     catch
     {
         return(View());
     }
 }
Example #3
0
        public ActionResult Index(string str)
        {
            using (DMSDBContext dc = new DMSDBContext())
            {
                List <ProfileVM> profileVM = new List <ProfileVM>();
                profileVM = dc.Users.Select(x => new ProfileVM
                {
                    FirstName = x.FirstName,
                    LastName  = x.LastName,
                    Email     = x.Email,
                    DeptName  = x.Department.DeptName,
                    UserId    = x.UserId
                }).ToList();

                if (!string.IsNullOrEmpty(str))
                {
                    var searcheditems = from x in profileVM.Where(x => x.FirstName.Contains(str) || x.LastName.Contains(str) || x.Email.Contains(str) || x.DeptName.Contains(str))
                                        select new ProfileVM
                    {
                        FirstName = x.FirstName,
                        LastName  = x.LastName,
                        Email     = x.Email,
                        DeptName  = x.DeptName,
                        UserId    = x.UserId
                    };
                    return(View(searcheditems));
                }
                return(View(profileVM));
            }
        }
Example #4
0
        public ActionResult Index(string str)
        {
            using (DMSDBContext dc = new DMSDBContext())
            {
                List <ProfileVM> profileVM = new List <ProfileVM>();
                profileVM = dc.Categories.Select(x => new ProfileVM
                {
                    CategoryName = x.CategoryName,
                    CategoryId   = x.CategoryId,
                    Email        = x.User.Email
                }).ToList();

                if (!string.IsNullOrEmpty(str))
                {
                    var searcheditems = from x in profileVM.Where(x => x.CategoryName.Contains(str) || x.Email.Contains(str))
                                        select new ProfileVM
                    {
                        CategoryName = x.CategoryName,
                        CategoryId   = x.CategoryId,
                        Email        = x.Email
                    };
                    return(View(searcheditems));
                }
                return(View(profileVM));
            }
        }
Example #5
0
        public ActionResult Create()
        {
            DMSDBContext dc = new DMSDBContext();

            TempData["Departments"] = new SelectList(dc.Departments, "DeptId", "DeptName");
            return(View());
        }
Example #6
0
        public ActionResult ChangePassword(ProfileVM profileVM)
        {
            try
            {
                using (DMSDBContext dc = new DMSDBContext())
                {
                    string message = "";

                    var validate = dc.Users.Where(a => a.Password == profileVM.Password).FirstOrDefault();
                    if (validate != null)
                    {
                        validate.Password        = profileVM.NewPassword;
                        dc.Entry(validate).State = EntityState.Modified;
                        dc.SaveChanges();

                        message             = "Password Changed Successfully";
                        TempData["Message"] = message;
                        return(RedirectToAction("Index", "Profile"));
                    }
                    else
                    {
                        message = "Input Valid Current Password";
                    }
                    ViewBag.Message = message;
                    return(View());
                }
            }
            catch
            {
                return(View());
            }
        }
Example #7
0
 public ActionResult Create(ProfileVM profileVM)
 {
     try
     {
         using (DMSDBContext dc = new DMSDBContext())
         {
             string message  = "";
             var    validate = dc.Departments.Where(a => a.DeptName == profileVM.DeptName).FirstOrDefault();
             if (validate == null)
             {
                 Department department = new Department();
                 department.DeptName = profileVM.DeptName;
                 dc.Departments.Add(department);
                 dc.SaveChanges();
                 message             = "Department Created Successfully";
                 TempData["Message"] = message;
                 return(RedirectToAction("Index", "Department"));
             }
             else
             {
                 message             = "This Department is already created. Please use another!!";
                 TempData["Message"] = message;
                 return(RedirectToAction("Create", "Department"));
             }
         }
     }
     catch
     {
         return(View());
     }
 }
Example #8
0
        public ActionResult Index()
        {
            using (DMSDBContext dc = new DMSDBContext())
            {
                var user       = dc.Users.Count();
                var department = dc.Departments.Count();
                var category   = dc.Categories.Count();
                if (User.IsInRole("Admin"))
                {
                    var document = dc.Documents.Count();
                    ViewBag.document = document;
                }
                else
                {
                    int id       = Convert.ToInt32(Session["id"]);
                    var document = dc.Documents.Where(x => x.UserId == id).Count();
                    ViewBag.document = document;
                }

                ViewBag.user       = user;
                ViewBag.department = department;
                ViewBag.category   = category;
                return(View());
            }
        }
Example #9
0
 public ActionResult Download(int id)
 {
     using (DMSDBContext dc = new DMSDBContext())
     {
         var    data = dc.Documents.Where(x => x.DocumentId == id).FirstOrDefault();
         string strPhysicalFolder = Server.MapPath("//Documents/" + data.Category.CategoryName + "/");
         string strFileFullPath   = strPhysicalFolder + data.DocumentName;
         return(File(strFileFullPath, System.Net.Mime.MediaTypeNames.Application.Octet, data.DocumentName));
     }
 }
Example #10
0
 public ActionResult Edit(int id)
 {
     using (DMSDBContext dc = new DMSDBContext())
     {
         var       profile   = dc.Departments.Where(x => x.DeptId == id).FirstOrDefault();
         ProfileVM profileVM = new ProfileVM()
         {
             DeptId   = profile.DeptId,
             DeptName = profile.DeptName,
         };
         return(View(profileVM));
     }
 }
Example #11
0
 public ActionResult Edit(int id)
 {
     using (DMSDBContext dc = new DMSDBContext())
     {
         var       data      = dc.Categories.Where(x => x.CategoryId == id).FirstOrDefault();
         ProfileVM profileVM = new ProfileVM()
         {
             CategoryId   = data.CategoryId,
             CategoryName = data.CategoryName,
         };
         return(View(profileVM));
     }
 }
Example #12
0
        public ActionResult ChangePassword()
        {
            string email = User.Identity.Name;

            using (DMSDBContext dc = new DMSDBContext())
            {
                var       profile   = dc.Users.FirstOrDefault(c => c.Email == email);
                ProfileVM profileVM = new ProfileVM()
                {
                    UserId = profile.UserId,
                };
                return(View(profileVM));
            }
        }
Example #13
0
        public ActionResult Index(string str)
        {
            using (DMSDBContext dc = new DMSDBContext())
            {
                List <ProfileVM> profileVM = new List <ProfileVM>();
                if (User.IsInRole("Admin"))
                {
                    profileVM = dc.Documents.Select(x => new ProfileVM
                    {
                        DocumentId      = x.DocumentId,
                        DocumentName    = x.DocumentName,
                        DocumentPath    = x.DocumentPath,
                        DocumentDetails = x.DocumentDetails,
                        CategoryName    = x.Category.CategoryName,
                        Email           = x.User.Email
                    }).ToList();
                }
                else
                {
                    int id = Convert.ToInt32(Session["id"]);


                    profileVM = dc.Documents.Where(x => x.UserId == id).Select(x => new ProfileVM
                    {
                        DocumentId      = x.DocumentId,
                        DocumentName    = x.DocumentName,
                        DocumentPath    = x.DocumentPath,
                        DocumentDetails = x.DocumentDetails,
                        CategoryName    = x.Category.CategoryName,
                        Email           = x.User.Email
                    }).ToList();
                }
                if (!string.IsNullOrEmpty(str))
                {
                    var searcheditems = from x in profileVM.Where(x => x.DocumentName.Contains(str) || x.DocumentName.Contains(str) || x.CategoryName.Contains(str) || x.Email.Contains(str))
                                        select new ProfileVM
                    {
                        DocumentId      = x.DocumentId,
                        DocumentName    = x.DocumentName,
                        DocumentPath    = x.DocumentPath,
                        DocumentDetails = x.DocumentDetails,
                        CategoryName    = x.CategoryName,
                        Email           = x.Email
                    };
                    return(View(searcheditems));
                }
                return(View(profileVM));
            }
        }
Example #14
0
        public ActionResult DocView(int id)
        {
            using (DMSDBContext dc = new DMSDBContext())
            {
                var data = dc.Documents.Where(x => x.DocumentId == id).FirstOrDefault();
                Gnostice.Documents.WebHandler.ViewerController viewerController =

                    new Gnostice.Documents.WebHandler.ViewerController();
                // Load the file present under App_Data folder
                String filenameWithPath = Server.MapPath("//Documents/" + data.Category.CategoryName + "/" + data.DocumentName);
                // Load the server-side document using the document URI
                ViewBag.docURI = viewerController.LoadDocument(filenameWithPath);
                return(View());
            }
        }
Example #15
0
 public ActionResult Create(HttpPostedFileBase file, ProfileVM profileVM)
 {
     try
     {
         using (DMSDBContext dc = new DMSDBContext())
         {
             string message  = "";
             int    id       = Convert.ToInt32(Session["id"]);
             string fileName = Path.GetFileName(file.FileName).Replace(" ", "");
             var    validate = (from p in dc.Documents
                                where (p.DocumentName == fileName) && (p.CategoryId == profileVM.CategoryId)
                                select p
                                ).FirstOrDefault();
             if (file.ContentLength > 0 && validate == null)
             {
                 var    category = dc.Categories.Where(a => a.CategoryId == profileVM.CategoryId).FirstOrDefault();
                 string path     = Path.Combine(Server.MapPath("//Documents/" + category.CategoryName));
                 if (!Directory.Exists(path))
                 {
                     Directory.CreateDirectory(path);
                 }
                 string   paths    = Path.Combine(Server.MapPath("//Documents/" + category.CategoryName), fileName);
                 Document document = new Document();
                 document.DocumentName    = fileName;
                 document.DocumentPath    = path.ToString();
                 document.DocumentDetails = profileVM.DocumentDetails;
                 document.CategoryId      = profileVM.CategoryId;
                 document.UserId          = id;
                 dc.Documents.Add(document);
                 dc.SaveChanges();
                 file.SaveAs(paths);
                 message             = "Document Uploaded Successfully";
                 TempData["Message"] = message;
                 return(RedirectToAction("Index", "Document"));
             }
             else
             {
                 message             = "Document size is zero OR same file name already present!!";
                 TempData["Message"] = message;
                 return(RedirectToAction("Create", "Document"));
             }
         }
     }
     catch
     {
         return(View());
     }
 }
Example #16
0
        public ActionResult Edit(int id)
        {
            DMSDBContext dc        = new DMSDBContext();
            var          profile   = dc.Users.Where(x => x.UserId == id).FirstOrDefault();
            ProfileVM    profileVM = new ProfileVM()
            {
                UserId    = profile.UserId,
                FirstName = profile.FirstName,
                LastName  = profile.LastName,
                Email     = profile.Email,
                DeptId    = profile.DeptId,
                DeptName  = profile.Department.DeptName
            };

            TempData["Departments"] = new SelectList(dc.Departments, "DeptId", "DeptName");
            return(View(profileVM));
        }
Example #17
0
        public ActionResult Index()
        {
            string email = User.Identity.Name;

            using (DMSDBContext dc = new DMSDBContext())
            {
                var       profile   = dc.Users.FirstOrDefault(c => c.Email == email);
                ProfileVM profileVM = new ProfileVM()
                {
                    UserId    = profile.UserId,
                    FirstName = profile.FirstName,
                    LastName  = profile.LastName,
                    Email     = profile.Email,
                    DeptName  = profile.Department.DeptName
                };
                return(View(profileVM));
            }
        }
Example #18
0
 public ActionResult Create()
 {
     using (DMSDBContext dc = new DMSDBContext())
     {
         var data   = dc.Categories.ToList();
         var result = new List <SelectListItem>();
         foreach (var item in data)
         {
             result.Add(new SelectListItem
             {
                 Value = item.CategoryId.ToString(),
                 Text  = item.CategoryName,
             });
         }
         TempData["category"] = new SelectList(result, "Value", "Text");
         return(View());
     }
 }
Example #19
0
 public ActionResult Delete(int id, ProfileVM profileVM)
 {
     try
     {
         using (DMSDBContext dc = new DMSDBContext())
         {
             var data = dc.Categories.Where(x => x.CategoryId == id).FirstOrDefault();
             dc.Categories.Remove(data);
             dc.SaveChanges();
             string message = "Category Deleted Successfully";
             TempData["Message"] = message;
             return(RedirectToAction("Index", "Category"));
         }
     }
     catch
     {
         string message = "You are trying to delete category which is currently used by users";
         TempData["Message"] = message;
         return(RedirectToAction("Index", "Category"));;
     }
 }
Example #20
0
 public ActionResult Delete(int id, ProfileVM profileVM)
 {
     try
     {
         using (DMSDBContext dc = new DMSDBContext())
         {
             var data = dc.Users.Where(x => x.UserId == id).FirstOrDefault();
             dc.Users.Remove(data);
             dc.SaveChanges();
             string message = "User Deleted Successfully";
             TempData["Message"] = message;
             return(RedirectToAction("Index", "User"));
         }
     }
     catch
     {
         string message = "You are trying to delete User who have file!!";
         TempData["Message"] = message;
         return(RedirectToAction("Index", "User"));
     }
 }
Example #21
0
 public ActionResult Login(ProfileVM loginVM)
 {
     using (DMSDBContext dc = new DMSDBContext())
     {
         string message  = "";
         var    validate = dc.Users.FirstOrDefault(x => x.Email == loginVM.Email && x.Password == loginVM.Password);
         if (validate != null)
         {
             var data = dc.Users.FirstOrDefault(a => a.Email == loginVM.Email);
             FormsAuthentication.SetAuthCookie(data.Email, false);
             Session["id"] = data.UserId;
             return(RedirectToAction("Index", "Home"));
         }
         else
         {
             message = "Invalid credential provided";
         }
         ViewBag.Message = message;
         return(View());
     }
 }
Example #22
0
 public ActionResult Delete(int id, ProfileVM profileVM)
 {
     try
     {
         using (DMSDBContext dc = new DMSDBContext())
         {
             var data = dc.Departments.Where(x => x.DeptId == id).FirstOrDefault();
             dc.Departments.Remove(data);
             dc.SaveChanges();
             string message = "Department Deleted Successfully";
             TempData["Message"] = message;
             return(RedirectToAction("Index", "Department"));
         }
     }
     catch
     {
         string message = "You are trying to delete department which is currently assigned to users";
         TempData["Message"] = message;
         return(RedirectToAction("Index", "Department"));
     }
 }
Example #23
0
        public ActionResult Create(ProfileVM profileVM)
        {
            try
            {
                using (DMSDBContext dc = new DMSDBContext())
                {
                    string message  = "";
                    var    validate = dc.Users.Where(a => a.Email == profileVM.Email).FirstOrDefault();
                    if (validate == null)
                    {
                        User user = new User();
                        user.FirstName = profileVM.FirstName;
                        user.LastName  = profileVM.LastName;
                        user.Email     = profileVM.Email;
                        user.Password  = profileVM.NewPassword;
                        user.DeptId    = profileVM.DeptId;
                        dc.Users.Add(user);
                        dc.SaveChanges();

                        SendEmail(user.Email, user.Password);
                        message             = "User Created Successfully";
                        TempData["Message"] = message;
                        return(RedirectToAction("Index", "User"));
                    }
                    else
                    {
                        message             = "This Email address is already Used. Please use another!!";
                        TempData["Message"] = message;
                        return(RedirectToAction("Create", "User"));
                    }
                }
            }
            catch
            {
                return(View());
            }
        }
Example #24
0
 public ActionResult Create(ProfileVM profileVM)
 {
     try
     {
         using (DMSDBContext dc = new DMSDBContext())
         {
             string message  = "";
             var    validate = dc.Categories.Where(a => a.CategoryName == profileVM.CategoryName).FirstOrDefault();
             if (validate == null)
             {
                 int      id       = Convert.ToInt32(Session["id"]);
                 Category category = new Category();
                 category.CategoryName = profileVM.CategoryName;
                 category.UserId       = id;
                 dc.Categories.Add(category);
                 dc.SaveChanges();
                 message             = "Category Created Successfully";
                 TempData["Message"] = message;
                 if (User.IsInRole("Admin"))
                 {
                     return(RedirectToAction("Index", "Category"));
                 }
                 return(RedirectToAction("Create", "Category"));
             }
             else
             {
                 message             = "This Category is already created. Please use another!!";
                 TempData["Message"] = message;
                 return(RedirectToAction("Create", "Category"));
             }
         }
     }
     catch
     {
         return(View());
     }
 }
Example #25
0
        public ActionResult Edit(ProfileVM profileVM)
        {
            string message = "";

            try
            {
                using (DMSDBContext dc = new DMSDBContext())
                {
                    var user = dc.Users.Where(x => x.UserId == profileVM.UserId).FirstOrDefault();
                    user.FirstName       = profileVM.FirstName;
                    user.LastName        = profileVM.LastName;
                    user.DeptId          = profileVM.DeptId;
                    dc.Entry(user).State = EntityState.Modified;
                    dc.SaveChanges();
                    message             = "User Edited Successfully";
                    TempData["Message"] = message;
                    return(RedirectToAction("Index", "User"));
                }
            }
            catch
            {
                return(View());
            }
        }