public ActionResult Delete(string filePath, int id)
        {
            bool isValid = RemoveFileFromServer(filePath);

            if (isValid)
            {
                HRMS_EMP_Attachment_Details model = db.HRMS_EMP_Attachment_Details.Find(id);
                db.HRMS_EMP_Attachment_Details.Remove(model);
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }
            return(RedirectToAction("Index"));
        }
        public ActionResult Index(long?ID, string name)
        {
            HRMS_EMP_Attachment_Details obj = new HRMS_EMP_Attachment_Details();

            ViewBag.Attachment_Type_ID = new SelectList(db.HRMS_ATTACHMENT_TYPE, "Attachment_Type_ID", "Attachment_Type_Name");

            long   emp_id = Convert.ToInt64(Session["id"]);
            string role   = db.Accounts.Where(x => x.ID == emp_id).Select(x => x.role).FirstOrDefault();

            if (role == "admin")
            {
                ViewBag.Role      = "admin";
                ViewData["users"] = db.HRMS_EMP_Attachment_Details.ToList();

                if (ID != null)  //different than other transaction pages
                {
                    obj.EMP_ID = ID.Value;
                }


                if (name == null)
                {
                    bool isExist = db.HRMS_EMP_Attachment_Details.Any(x => x.EMP_ID == obj.EMP_ID);
                    if (isExist)
                    {
                        return(RedirectToAction("Create", "EmployeePhotoSign", new { ID = obj.EMP_ID }));
                    }
                }

                else
                {
                    bool isExist = db.HRMS_EMP_Attachment_Details.Any(x => x.EMP_ID == obj.EMP_ID);
                    if (isExist)
                    {
                        return(View(obj));
                    }
                    else
                    {
                        return(View(obj));
                    }
                }
            }

            else
            {
                ViewData["users"] = db.HRMS_EMP_Attachment_Details.Where(x => x.EMP_ID == emp_id).ToList();
            }

            return(View(obj));
        }
        public ActionResult Index(HttpPostedFileBase files, HRMS_EMP_Attachment_Details model)
        {
            long   emp_id = Convert.ToInt64(Session["id"]);
            string role   = db.Accounts.Where(x => x.ID == emp_id).Select(x => x.role).FirstOrDefault();

            if (role == "emp")
            {
                //ModelState.Remove("EMP_ID");
                model.EMP_ID = emp_id;
            }


            if (files != null)
            {
                //files already there or not
                bool IsValid = db.HRMS_EMP_Attachment_Details.Any(x => (x.EMP_ID == model.EMP_ID && x.Attachment_Type_ID == model.Attachment_Type_ID));
                if (IsValid)
                {
                    ViewBag.IsExist            = "File is already Uploaded!";
                    ViewBag.Attachment_Type_ID = new SelectList(db.HRMS_ATTACHMENT_TYPE, "Attachment_Type_ID", "Attachment_Type_Name");
                    if (role == "admin")
                    {
                        ViewBag.Role      = "admin";
                        ViewData["users"] = db.HRMS_EMP_Attachment_Details.ToList();
                    }

                    else
                    {
                        ViewData["users"] = db.HRMS_EMP_Attachment_Details.Where(x => x.EMP_ID == emp_id).ToList();
                    }
                    return(View(model));
                }

                else
                {
                    //fetching Attachment Name from Attachment ID
                    var AttachmentName = db.HRMS_ATTACHMENT_TYPE.Where(x => x.Attachment_Type_ID == model.Attachment_Type_ID).Select(x => x.Attachment_Type_Name).FirstOrDefault();

                    var Extension = Path.GetExtension(files.FileName);

                    //only pdf
                    if (Extension == ".pdf" || Extension == ".PDF")
                    {
                        var    fileName = model.EMP_ID + "_" + AttachmentName + Extension;
                        string path     = Path.Combine(Server.MapPath("~/UploadedFiles"), fileName);
                        model.FILEURL  = Url.Content(Path.Combine("~/UploadedFiles/", fileName));
                        model.FILENAME = fileName;
                        files.SaveAs(path);
                        db.HRMS_EMP_Attachment_Details.Add(model);
                        db.SaveChanges();
                        ModelState.Clear();

                        ViewBag.Success            = "File is Succeccfully Uploaded!";
                        ViewBag.Attachment_Type_ID = new SelectList(db.HRMS_ATTACHMENT_TYPE, "Attachment_Type_ID", "Attachment_Type_Name");

                        if (role == "admin")
                        {
                            ViewBag.Role      = "admin";
                            ViewData["users"] = db.HRMS_EMP_Attachment_Details.ToList();
                            return(RedirectToAction("Create", "EmployeePhotoSign", new { ID = model.EMP_ID }));
                        }

                        else
                        {
                            ViewData["users"] = db.HRMS_EMP_Attachment_Details.Where(x => x.EMP_ID == emp_id).ToList();
                        }
                        return(View(model));
                    }

                    else
                    {
                        ViewBag.Format             = "Please Upload only pdf format!";
                        ViewBag.Attachment_Type_ID = new SelectList(db.HRMS_ATTACHMENT_TYPE, "Attachment_Type_ID", "Attachment_Type_Name");
                        if (role == "admin")
                        {
                            ViewBag.Role      = "admin";
                            ViewData["users"] = db.HRMS_EMP_Attachment_Details.ToList();
                        }

                        else
                        {
                            ViewData["users"] = db.HRMS_EMP_Attachment_Details.Where(x => x.EMP_ID == emp_id).ToList();
                        }
                        return(View(model));
                    }
                }
            }
            else
            {
                ModelState.AddModelError("", "Please Choose Correct File Type !!");
                ViewBag.Attachment_Type_ID = new SelectList(db.HRMS_ATTACHMENT_TYPE, "Attachment_Type_ID", "Attachment_Type_Name");
                if (role == "admin")
                {
                    ViewBag.Role      = "admin";
                    ViewData["users"] = db.HRMS_EMP_Attachment_Details.ToList();
                }

                else
                {
                    ViewData["users"] = db.HRMS_EMP_Attachment_Details.Where(x => x.EMP_ID == emp_id).ToList();
                }
                return(View(model));
            }
        }