Ejemplo n.º 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());
     }
 }
Ejemplo n.º 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());
     }
 }
Ejemplo n.º 3
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());
     }
 }
Ejemplo n.º 4
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());
            }
        }
Ejemplo n.º 5
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());
     }
 }
Ejemplo n.º 6
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"));
     }
 }
Ejemplo n.º 7
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"));
     }
 }
Ejemplo n.º 8
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"));;
     }
 }
Ejemplo n.º 9
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());
            }
        }
Ejemplo n.º 10
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());
     }
 }
Ejemplo n.º 11
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());
            }
        }