// GET: EmployeeGIs/Create
 public ActionResult Create()
 {
     try
     {
         EmployeeGI empgi = new EmployeeGI();
         empgi.DateOfBirth    = DateTime.Now.Date.AddYears(-18).Date;
         ViewBag.EmployeeCode = new SelectList(db.EmployeeGIs, "EmployeeCode", "EmployeeCode");
         List <SelectListItem> File_Nos = new List <SelectListItem>();
         for (int i = 1; i <= 111; i++)
         {
             File_Nos.Add(new SelectListItem {
                 Text = i.ToString(), Value = i.ToString()
             });
         }
         var user = (UserMaster)Session["User"];
         ViewBag.File_Nos             = new SelectList(File_Nos, "Value", "Text");
         ViewBag.Ranks                = new SelectList(db.RankMasters.Where(item => item.CustomerId == user.CustomerId), "RankName", "RankName");
         ViewBag.LGAs                 = new SelectList(db.CityMasters, "City", "City");
         ViewBag.StateOfOrigins       = new SelectList(db.StateMasters, "State", "State");
         ViewBag.cadres               = new SelectList(db.CadreMasters.Where(item => item.CustomerId == user.CustomerId), "CadreName", "CadreName");
         ViewBag.Programmess          = new SelectList(db.ProgrammeMasters.Where(item => item.CustomerId == user.CustomerId), "ProgrammeName", "ProgrammeName");
         ViewBag.Unit_Researchs       = new SelectList(db.UnitResearchMasters.Where(item => item.CustomerId == user.CustomerId), "UnitResearchName", "UnitResearchName");
         ViewBag.Unit_Servicess       = new SelectList(db.UnitServicesMasters.Where(item => item.CustomerId == user.CustomerId), "UnitServicesName", "UnitServicesName");
         ViewBag.StationOfDeployments = new SelectList(db.StationMasters.Where(item => item.CustomerId == user.CustomerId), "StationName", "StationName");
         ViewBag.Sections             = new SelectList(db.SectionMasters.Where(item => item.CustomerId == user.CustomerId), "SectionName", "SectionName");
         return(View(empgi));
     }
     catch (Exception ext)
     {
         return(null);
     }
 }
        public ActionResult Edit(EmployeeGI tenent)
        {
            if (ModelState.IsValid)
            {
                var tenentUpdate = db.EmployeeGIs.Find(tenent.EmployeeCode);
                tenentUpdate.First_Name               = tenent.First_Name;
                tenentUpdate.Surname                  = tenent.Surname;
                tenentUpdate.Sex                      = tenent.Sex;
                tenentUpdate.DateOfBirth              = tenent.DateOfBirth;
                tenentUpdate.Maiden_Name              = tenent.Maiden_Name;
                tenentUpdate.Middle_Name              = tenent.Middle_Name;
                tenentUpdate.Title                    = tenent.Title;
                tenentUpdate.StateOfOrigin            = tenent.StateOfOrigin;
                tenentUpdate.LGA                      = tenent.LGA;
                tenentUpdate.Religion                 = tenent.Religion;
                tenentUpdate.DateOfRetirement         = tenent.DateOfRetirement;
                tenentUpdate.EmployeeCode             = tenent.EmployeeCode;
                tenentUpdate.Unit_Research            = tenent.Unit_Research;
                tenentUpdate.Section                  = tenent.Section;
                tenentUpdate.StationOfDeployment      = tenent.StationOfDeployment;
                tenentUpdate.File_No                  = tenent.File_No;
                tenentUpdate.Grade_Level              = tenent.Grade_Level;
                tenentUpdate.Step                     = tenent.Step;
                tenentUpdate.Cadre                    = tenent.Cadre;
                tenentUpdate.Marital_Status           = tenent.Marital_Status;
                tenentUpdate.PlaceOfBirth             = tenent.PlaceOfBirth;
                tenentUpdate.Home_Town                = tenent.Home_Town;
                tenentUpdate.ContactHomeAddress       = tenent.ContactHomeAddress;
                tenentUpdate.FirstAppointmentDate     = tenent.FirstAppointmentDate;
                tenentUpdate.FirstAppointmentLocation = tenent.FirstAppointmentLocation;
                tenentUpdate.ConfirmationDate         = tenent.ConfirmationDate;
                tenentUpdate.LastPromotionDate        = tenent.LastPromotionDate;
                tenentUpdate.Rank                     = tenent.Rank;
                db.Entry(tenentUpdate).State          = EntityState.Modified;
                var customerUpdate = db.CustomerMasters.Find(tenentUpdate.CustomerId);
                customerUpdate.ContactPerson  = tenent.CustomerMaster.ContactPerson = (tenent.First_Name + " " + tenent.Middle_Name + " " + tenent.Surname).Trim();
                customerUpdate.OrgLogoUrl     = tenent.CustomerMaster.OrgLogoUrl;
                customerUpdate.CountryLogoIrl = tenent.CustomerMaster.CountryLogoIrl;
                customerUpdate.OrgName        = tenent.CustomerMaster.OrgName;
                customerUpdate.Email          = tenent.CustomerMaster.Email;
                customerUpdate.Address        = tenent.CustomerMaster.Address;
                customerUpdate.PhoneNumber    = tenent.CustomerMaster.PhoneNumber;
                customerUpdate.CountryLogo    = tenent.CustomerMaster.CountryLogo;
                customerUpdate.CountryLogoIrl = tenent.CustomerMaster.CountryLogoIrl;
                customerUpdate.OrgLogo        = tenent.CustomerMaster.OrgLogo;
                customerUpdate.OrgLogoUrl     = tenent.CustomerMaster.OrgLogoUrl;


                SaveImages(customerUpdate);
                db.Entry(customerUpdate).State = EntityState.Modified;
                var user = db.UserMasters.Where(um => um.CustomerId == tenent.CustomerId).FirstOrDefault();
                user.Password        = tenent.CustomerMaster.UserMaster.Password;
                db.Entry(user).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(tenent));
        }
        // GET: CustomerMasters/Create
        public ActionResult Create()
        {
            ViewBag.LGAs           = new SelectList(db.CityMasters.Where(c => c.StateId == 1), "City", "City");
            ViewBag.StateOfOrigins = new SelectList(db.StateMasters, "State", "State");
            var emp = new EmployeeGI()
            {
                CustomerMaster = new CustomerMaster()
            };

            return(View());
        }
        ///
        // GET: EmployeeGIs/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            EmployeeGI employeeGI = db.EmployeeGIs.Find(id);

            if (employeeGI == null)
            {
                return(HttpNotFound());
            }
            return(View(employeeGI));
        }
 public ActionResult Create(EmployeeGI tenent)
 {
     if (ModelState.IsValid)
     {
         if (AddNewTenant(tenent))
         {
             TempData["NewTenent"] = tenent.CustomerMaster;
             return(RedirectToAction("Index", "Tenant"));
         }
     }
     ViewBag.LGAs           = new SelectList(db.CityMasters.Where(c => c.StateId == 1), "City", "City");
     ViewBag.StateOfOrigins = new SelectList(db.StateMasters, "State", "State");
     return(View(tenent));
 }
        private bool AddNewTenant(EmployeeGI tenent)
        {
            var isSaved = false;

            try
            {
                tenent.CustomerMaster.ContactPerson = tenent.CustomerMaster.ContactPerson = (tenent.First_Name + " " + tenent.Middle_Name + " " + tenent.Surname).Trim();
                tenent.DateOfRetirement             = DateTime.Now.AddYears(20);
                tenent.EmployeeCode = (db.EmployeeGIs.Any()) ? (db.EmployeeGIs.Max(e => e.EmployeeCode) + 1) : 1000;
                var loginUser = new UserMaster()
                {
                    EmployeeCode = tenent.EmployeeCode,
                    EmailId      = "Update Your Mail Id",
                    UserName     = tenent.EmployeeCode.ToString(),
                    Password     = "******" + tenent.EmployeeCode.ToString(),
                    RoleId       = 1,
                    RoleName     = "Admin",
                };
                db.UserMasters.Add(loginUser);
                db.SaveChanges();
                tenent.CustomerMaster.LoginUserId  = loginUser.UserId;
                tenent.CustomerMaster.EmployeeGIId = tenent.EmployeeGIId;
                db.EmployeeGIs.Add(tenent);
                db.SaveChanges();
                tenent.CustomerMaster.EmployeeGIId = tenent.EmployeeGIId;
                loginUser.CustomerId = tenent.CustomerId;
                var isImagesSaved = SaveImages(tenent.CustomerMaster);
                var isConfigSaved = AddSystemConfig(tenent);
                isSaved = isImagesSaved && isConfigSaved;
                var rank = db.RankMasters.Where(r => r.CustomerId == tenent.CustomerMaster.CustomerId).FirstOrDefault()?.RankName;
                tenent.Rank = !string.IsNullOrEmpty(rank) ? rank : string.Empty;
                db.SaveChanges();
                tenent.CustomerMaster.EmployeeGIId = tenent.EmployeeGIId;
                tenent.CustomerId                     = tenent.CustomerMaster.CustomerId;
                loginUser.CustomerId                  = tenent.CustomerMaster.CustomerId;
                db.Entry(loginUser).State             = EntityState.Modified;
                db.Entry(tenent.CustomerMaster).State = EntityState.Modified;
                db.Entry(tenent).State                = EntityState.Modified;
                tenent.CustomerMaster.UserMaster      = loginUser;
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                var msg = ex.Message;
                isSaved = false;
            }
            return(isSaved);
        }
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            var        empCode = (from emp in db.EmployeeGIs where emp.EmployeeGIId == id.Value select emp.EmployeeCode).FirstOrDefault();
            EmployeeGI tenent  = db.EmployeeGIs.Find(empCode);

            tenent.CustomerMaster = db.CustomerMasters.Find(tenent.CustomerId);
            if (tenent == null)
            {
                return(HttpNotFound());
            }
            ViewBag.LGAs           = new SelectList(db.CityMasters.Where(c => c.StateId == 1), "City", "City");
            ViewBag.StateOfOrigins = new SelectList(db.StateMasters, "State", "State");
            return(View(tenent));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            try
            {
                EmployeeGI employeeGI = db.EmployeeGIs.Find(id);
                db.EmployeeGIs.Remove(employeeGI);
                db.SaveChanges();

                db.SaveChanges();
                TempData["successmsg"] = "Record is Successfully Deleted";
                TempData["msg"]        = "";
            }
            catch (Exception ext)
            {
                TempData["successmsg"] = "";
                TempData["msg"]        = "Please delete Other Information records of this Employee, before General Information deletion";
            }
            return(RedirectToAction("Index"));
        }
        private bool AddSystemConfig(EmployeeGI tenent)
        {
            // var path = "E:/MyProjects/AmitSoni-McAutomation/IARTAutomationApp/App_Data/SystemConfig.xlsx";
            string           filepath    = Server.MapPath("~/App_Data/SystemConfig.xlsx");
            FileStream       fs          = System.IO.File.Open(filepath, FileMode.Open, FileAccess.Read);
            IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(fs);
            DataSet          ds          = excelReader.AsDataSet();

            fs.Close();
            db.RankMasters.AddRange(AddRank(ds.Tables["Rank"].Rows, tenent.CustomerId.Value));// Not reading from excel as data is not avilable in excel.
            db.CadreMasters.AddRange(AddCadres(ds.Tables["Cadre"].Rows, tenent.CustomerId.Value));
            db.ProgrammeMasters.AddRange(AddProgrammeMasters(ds.Tables["Programmes"].Rows, tenent.CustomerId.Value));
            db.UnitResearchMasters.AddRange(AddUnitResearchMaster(ds.Tables["Unit - Research"].Rows, tenent.CustomerId.Value));
            db.UnitServicesMasters.AddRange(AddUnitServicesMaster(ds.Tables["Unit - Service"].Rows, tenent.CustomerId.Value));
            db.StationMasters.AddRange(AddStationOfDeployment(ds.Tables["Station of Deployment"].Rows, tenent.CustomerId.Value));
            db.SectionMasters.AddRange(AddSectionMaster(ds.Tables["Section"].Rows, tenent.CustomerId.Value));
            db.BankTypeMasters.AddRange(AddTypeOfBank(ds.Tables["Bank Types"].Rows, tenent.CustomerId.Value));
            db.BankMasters.AddRange(AddBank(ds.Tables["Bank Names"].Rows, tenent.CustomerId.Value));
            db.PFAMasters.AddRange(AddPFAMaster(ds.Tables["PFA"].Rows, tenent.CustomerId.Value));
            return(db.SaveChanges() > 0 ? true : false);
        }
 public ActionResult MidLevelEdit([Bind(Include = "EmployeeGIId,EmployeeCode,Rank,File_No,Grade_Level,Step,Cadre,Title,First_Name,Middle_Name,Surname,Sex,DateOfBirth,PlaceOfBirth,Marital_Status,Maiden_Name,Spouse_Name,StateOfOrigin,LGA,Home_Town,Religion,ContactHomeAddress,FirstAppointmentDate,FirstAppointmentLocation,ConfirmationDate,DateOfRetirement,LastPromotionDate,Programmes,Unit_Services,Unit_Research,Section,LeaveDays,Leave_fromDate,Leave_ToDate,EmployeePhoto,EmployeePhotoImage,StationOfDeployment,IsDeleted,CreatedDate")] EmployeeGI employeeGI)
 {
     try
     {
         if (employeeGI.EmployeePhotoImage != null && employeeGI.EmployeePhotoImage.ContentLength > 0)
         {
             var uploadDir = "~/uploads";
             var imagePath = Path.Combine(Server.MapPath(uploadDir), employeeGI.EmployeePhotoImage.FileName.ToString());
             var imageUrl  = Path.Combine(uploadDir, employeeGI.EmployeePhotoImage.FileName.ToString());
             employeeGI.EmployeePhoto = employeeGI.EmployeePhotoImage.FileName.ToString();
             employeeGI.EmployeePhotoImage.SaveAs(imagePath);
         }
         if (employeeGI.Marital_Status != "Married")
         {
             employeeGI.Spouse_Name = "N/A";
         }
         employeeGI.Leave_fromDate = DateTime.Now.Date;
         employeeGI.Leave_ToDate   = DateTime.Now.Date;
         TimeSpan daydiff = Convert.ToDateTime(employeeGI.Leave_ToDate) - Convert.ToDateTime(employeeGI.Leave_fromDate);
         employeeGI.LeaveDays       = daydiff.Days;
         employeeGI.CreatedDate     = DateTime.Now.Date;
         employeeGI.IsDeleted       = false;
         db.Entry(employeeGI).State = EntityState.Modified;
         db.SaveChanges();
         TempData["successmsg"] = "Record is Successfully Updated";
         TempData["msg"]        = "";
         int empcode = Convert.ToInt32(@Session["employeecode"]);
         return(RedirectToAction("MidLevelIndex"));
     }
     catch (Exception ext)
     {
         TempData["successmsg"] = "";
         TempData["msg"]        = "Record is not Updated,Try again";
     }
     return(RedirectToAction("Index"));
 }
        // GET: EmployeeGIs/Edit/5
        public ActionResult MidLevelEdit(int?id)
        {
            EmployeeGI employeeGI = db.EmployeeGIs.Find(id);

            List <SelectListItem> File_Nos = new List <SelectListItem>();

            File_Nos.Add(new SelectListItem {
                Text = "Select", Value = "0"
            });
            for (int i = 1; i <= 200; i++)
            {
                //if (i != 9)
                File_Nos.Add(new SelectListItem {
                    Text = i.ToString(), Value = i.ToString()
                });
                //else
                //    File_Nos.Add(new SelectListItem { Text = i.ToString(), Value = i.ToString(), Selected = true });
            }

            List <SelectListItem> Titles = new List <SelectListItem>();

            //Titles.Add(new SelectListItem { Text = "Select", Value = "0" });
            Titles.Add(new SelectListItem {
                Text = "Mr", Value = "0"
            });
            Titles.Add(new SelectListItem {
                Text = "Mrs", Value = "1"
            });
            Titles.Add(new SelectListItem {
                Text = "Miss", Value = "2"
            });
            Titles.Add(new SelectListItem {
                Text = "Dr", Value = "3"
            });
            Titles.Add(new SelectListItem {
                Text = "Prof", Value = "4"
            });
            ViewBag.Titles = new SelectList(Titles, "Text", "Text");

            List <SelectListItem> Steps = new List <SelectListItem>();

            Steps.Add(new SelectListItem {
                Text = "Select", Value = "0"
            });
            for (int i = 1; i <= 15; i++)
            {
                Steps.Add(new SelectListItem {
                    Text = i.ToString(), Value = i.ToString()
                });
            }
            List <SelectListItem> Grades = new List <SelectListItem>();

            Grades.Add(new SelectListItem {
                Text = "Select", Value = "0"
            });
            for (int i = 1; i <= 15; i++)
            {
                Grades.Add(new SelectListItem {
                    Text = i.ToString(), Value = i.ToString()
                });
            }
            //ViewBag.File_No = new SelectList(File_Nos, "Value", "Text", employeeGI.File_No);

            ViewBag.Steps        = new SelectList(Steps, "Value", "Text");
            ViewBag.Grade_Levels = new SelectList(Grades, "Value", "Text");
            //ViewBag.Rank = new SelectList(db.RankMasters, "RankName", "RankName", employeeGI.Rank);
            //ViewBag.LGA = new SelectList(db.CityMasters, "City", "City", employeeGI.LGA);
            //ViewBag.StateOfOrigin = new SelectList(db.StateMasters, "State", "State", employeeGI.StateOfOrigin);
            //ViewBag.cadre = new SelectList(db.CadreMasters, "CadreName", "CadreName");
            //ViewBag.Programmes = new SelectList(db.ProgrammeMasters, "ProgrammeName", "ProgrammeName");
            //ViewBag.Unit_Research = new SelectList(db.UnitResearchMasters, "UnitResearchName", "UnitResearchName");
            //ViewBag.Unit_Services = new SelectList(db.UnitServicesMasters, "UnitServicesName", "UnitServicesName");
            //ViewBag.StationOfDeployment = new SelectList(db.StationMasters, "StationName", "StationName");
            //ViewBag.Section = new SelectList(db.SectionMasters, "SectionName", "SectionName");
            ViewBag.File_Noa = new SelectList(File_Nos, "Value", "Text");

            ///////
            ViewBag.Ranks                = new SelectList(db.RankMasters, "RankName", "RankName");
            ViewBag.LGAs                 = new SelectList(db.CityMasters, "City", "City");
            ViewBag.StateOfOrigins       = new SelectList(db.StateMasters, "State", "State");
            ViewBag.cadres               = new SelectList(db.CadreMasters, "CadreName", "CadreName");
            ViewBag.Programmess          = new SelectList(db.ProgrammeMasters, "ProgrammeName", "ProgrammeName");
            ViewBag.Unit_Researchs       = new SelectList(db.UnitResearchMasters, "UnitResearchName", "UnitResearchName");
            ViewBag.Unit_Servicess       = new SelectList(db.UnitServicesMasters, "UnitServicesName", "UnitServicesName");
            ViewBag.StationOfDeployments = new SelectList(db.StationMasters, "StationName", "StationName");
            ViewBag.Sections             = new SelectList(db.SectionMasters, "SectionName", "SectionName");

            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            if (employeeGI == null)
            {
                return(HttpNotFound());
            }
            ViewBag.EmployeeCode = new SelectList(db.EmployeeGIs, "EmployeeCode", "EmployeeCode", employeeGI.EmployeeCode);

            return(View(employeeGI));
        }
        //[ValidateAntiForgeryToken]
        public ActionResult MidLevelCreate([Bind(Include = "EmployeeGIId,EmployeeCode,Rank,File_No,Grade_Level,Step,Cadre,Title,First_Name,Middle_Name,Surname,Sex,DateOfBirth,PlaceOfBirth,Marital_Status,Maiden_Name,Spouse_Name,StateOfOrigin,LGA,Home_Town,Religion,ContactHomeAddress,FirstAppointmentDate,FirstAppointmentLocation,ConfirmationDate,DateOfRetirement,LastPromotionDate,Programmes,Unit_Services,Unit_Research,Section,LeaveDays,Leave_fromDate,Leave_ToDate,,EmployeePhotoImage,StationOfDeployment,IsDeleted,CreatedDate")] EmployeeGI employeeGI)
        {
            try
            {
                if (employeeGI.Marital_Status != "Married")
                {
                    employeeGI.Spouse_Name = "N/A";
                }

                var list = new List <int>();
                for (int i = 1; i <= 111; i++)
                {
                    list.Add(i);
                }
                List <SelectListItem> File_Nos = new List <SelectListItem>();
                File_Nos.Add(new SelectListItem {
                    Text = "Select", Value = "0"
                });
                for (int i = 1; i <= 111; i++)
                {
                    File_Nos.Add(new SelectListItem {
                        Text = i.ToString(), Value = i.ToString()
                    });
                }

                ViewBag.File_No              = new SelectList(File_Nos, "Value", "Text");
                employeeGI.CreatedDate       = DateTime.Now.Date;
                employeeGI.IsDeleted         = false;
                ViewBag.Ranks                = new SelectList(db.RankMasters, "RankName", "RankName");
                ViewBag.LGAs                 = new SelectList(db.CityMasters, "City", "City");
                ViewBag.StateOfOrigins       = new SelectList(db.StateMasters, "State", "State");
                ViewBag.cadres               = new SelectList(db.CadreMasters, "CadreName", "CadreName");
                ViewBag.Programmess          = new SelectList(db.ProgrammeMasters, "ProgrammeName", "ProgrammeName");
                ViewBag.Unit_Researchs       = new SelectList(db.UnitResearchMasters, "UnitResearchName", "UnitResearchName");
                ViewBag.Unit_Servicess       = new SelectList(db.UnitServicesMasters, "UnitServicesName", "UnitServicesName");
                ViewBag.StationOfDeployments = new SelectList(db.StationMasters, "StationName", "StationName");
                ViewBag.Sections             = new SelectList(db.SectionMasters, "SectionName", "SectionName");

                //if (ModelState.IsValid)
                //{

                if (employeeGI.EmployeePhotoImage.FileName != null && employeeGI.EmployeePhotoImage.ContentLength > 0)
                {
                    var uploadDir = "~/uploads";
                    var imagePath = Path.Combine(Server.MapPath(uploadDir), employeeGI.EmployeePhotoImage.FileName.ToString());
                    var imageUrl  = Path.Combine(uploadDir, employeeGI.EmployeePhotoImage.FileName.ToString());
                    employeeGI.EmployeePhoto = employeeGI.EmployeePhotoImage.FileName.ToString();
                    employeeGI.EmployeePhotoImage.SaveAs(imagePath);
                }



                employeeGI.File_No = employeeGI.File_No;

                employeeGI.EmployeeGIId = employeeGI.EmployeeCode;
                db.EmployeeGIs.Add(employeeGI);
                db.SaveChanges();
                TempData["successmsg"] = "Record is Successfully added";
                TempData["msg"]        = "";

                return(RedirectToAction("MidLevelIndex"));
                //int empcode = Convert.ToInt32(@Session["employeecode"]);

                //DateTime dttoday = DateTime.Now.Date;
                //var Role = (from a in db.UserMasters where a.EmployeeCode == empcode select a.RoleId).FirstOrDefault();
                //var RoleName = (from b in db.RoleMasters where b.RoleId == Role select b.RoleName).FirstOrDefault();
                //if (RoleName == "Admin" || RoleName == "Super Admin")
                //{
                //    return RedirectToAction("Index");
                //}
                //else if (RoleName == "Mid Level Admin")
                //{
                //    return RedirectToAction("MidLevelIndex");
                //}
                //else if (RoleName == "Low Level Admin")
                //{
                //    return RedirectToAction("MidLevelIndex");
                //}
                //else
                //{
                //    return RedirectToAction("UserIndex");
                //}
            }
            catch (Exception ext)
            {
                TempData["successmsg"] = "";
                TempData["msg"]        = "Record is not added,Try again";
            }
            ViewBag.EmployeeCode = new SelectList(db.EmployeeGIs, "EmployeeCode", "EmployeeCode", employeeGI.EmployeeCode);
            return(View(employeeGI));
        }
        // GET: EmployeeGIs/Create
        public ActionResult MidLevelCreate()
        {
            try
            {
                EmployeeGI empgi = new EmployeeGI();
                //empgi.DateOfBirth = DateTime.Now.Date.AddYears(-18).Date;

                ViewBag.EmployeeCode = new SelectList(db.EmployeeGIs, "EmployeeCode", "EmployeeCode");

                List <SelectListItem> File_Nos = new List <SelectListItem>();
                File_Nos.Add(new SelectListItem {
                    Text = "Select", Value = "0"
                });
                for (int i = 1; i <= 111; i++)
                {
                    File_Nos.Add(new SelectListItem {
                        Text = i.ToString(), Value = i.ToString()
                    });
                }

                ViewBag.File_Nos = new SelectList(File_Nos, "Value", "Text");

                ///////
                ViewBag.Ranks                = new SelectList(db.RankMasters, "RankName", "RankName");
                ViewBag.LGAs                 = new SelectList(db.CityMasters, "City", "City");
                ViewBag.StateOfOrigins       = new SelectList(db.StateMasters, "State", "State");
                ViewBag.cadres               = new SelectList(db.CadreMasters, "CadreName", "CadreName");
                ViewBag.Programmess          = new SelectList(db.ProgrammeMasters, "ProgrammeName", "ProgrammeName");
                ViewBag.Unit_Researchs       = new SelectList(db.UnitResearchMasters, "UnitResearchName", "UnitResearchName");
                ViewBag.Unit_Servicess       = new SelectList(db.UnitServicesMasters, "UnitServicesName", "UnitServicesName");
                ViewBag.StationOfDeployments = new SelectList(db.StationMasters, "StationName", "StationName");
                ViewBag.Sections             = new SelectList(db.SectionMasters, "SectionName", "SectionName");



                //List<RankMaster> Ranklist = new List<RankMaster>();
                //Ranklist = (from a in db.RankMasters select a).ToList();
                ////ViewBag.CountryList = CountryList;
                //ViewBag.Rank = new SelectList(Ranklist, "RankId", "RankName");

                ///////

                //List<CityMaster> CityList = new List<CityMaster>();
                //CityList = (from a in db.CityMasters select a).ToList();
                ////ViewBag.CountryList = CountryList;
                //ViewBag.LGA = new SelectList(CityList, "Id", "City");
                ///////
                //List<StateMaster> StateList = new List<StateMaster>();
                //StateList = (from State in db.StateMasters select State).ToList();
                ////ViewBag.CountryList = CountryList;
                //ViewBag.StateOfOrigin = new SelectList(StateList, "Id", "State");
                ///////

                //List<CadreMaster> cadrelist = new List<CadreMaster>();
                //cadrelist = (from a in db.CadreMasters select a).ToList();
                ////ViewBag.CountryList = CountryList;
                //ViewBag.cadre = new SelectList(cadrelist, "CadreId", "CadreName");

                ///////

                //List<ProgrammeMaster> Programlist = new List<ProgrammeMaster>();
                //Programlist = (from a in db.ProgrammeMasters select a).ToList();
                ////ViewBag.CountryList = CountryList;
                //ViewBag.Programmes = new SelectList(Programlist, "ProgrammeId", "ProgrammeName");

                ///////

                //List<UnitResearchMaster> UnitResearchlist = new List<UnitResearchMaster>();
                //UnitResearchlist = (from a in db.UnitResearchMasters select a).ToList();
                ////ViewBag.CountryList = CountryList;
                //ViewBag.Unit_Research = new SelectList(UnitResearchlist, "UnitResearchId", "UnitResearchName");

                ///////

                //List<UnitServicesMaster> UnitServicelist = new List<UnitServicesMaster>();
                //UnitServicelist = (from a in db.UnitServicesMasters select a).ToList();
                ////ViewBag.CountryList = CountryList;
                //ViewBag.Unit_Services = new SelectList(UnitServicelist, "UnitServicesId", "UnitServicesName");

                ///////

                //List<StationMaster> Stationlist = new List<StationMaster>();
                //Stationlist = (from a in db.StationMasters select a).ToList();
                ////ViewBag.CountryList = CountryList;
                //ViewBag.StationOfDeployment = new SelectList(Stationlist, "StationId", "StationName");


                ///////

                //List<SectionMaster> Sectionlist = new List<SectionMaster>();
                //Sectionlist = (from a in db.SectionMasters select a).ToList();
                ////ViewBag.CountryList = CountryList;
                //ViewBag.Section = new SelectList(Sectionlist, "SectionId", "SectionName");


                return(View(empgi));
            }
            catch (Exception ext)
            {
                return(null);
            }
        }
        public JsonResult Edit(EmployeeAI obj, List <EmpAIAssociation> ObjAssociation, List <EmpAIConference> ObjConferenece)
        {
            int insertedRecords = 0;

            try
            {
                var        id       = (from a in db.EmployeeAIs where a.EmployeeCode == obj.EmployeeCode select a.EmployeeAIId).FirstOrDefault();
                var        idgI     = (from a in db.EmployeeGIs where a.EmployeeCode == obj.EmployeeCode select a.EmployeeGIId).FirstOrDefault();
                EmployeeGI objempGi = db.EmployeeGIs.Find(idgI);
                EmployeeAI objdest  = db.EmployeeAIs.Find(id);

                objdest.EmployeeCode                  = obj.EmployeeCode;
                objdest.InstitutionAttended1          = obj.InstitutionAttended1;
                objdest.InstitutionAttended2          = obj.InstitutionAttended2;
                objdest.InstitutionAttended3          = obj.InstitutionAttended3;
                objdest.Qualification1                = obj.Qualification1;
                objdest.Qualification2                = obj.Qualification2;
                objdest.Qualification3                = obj.Qualification3;
                objdest.YearOfGraduation1             = obj.YearOfGraduation1;
                objdest.YearOfGraduation2             = obj.YearOfGraduation2;
                objdest.YearOfGraduation3             = obj.YearOfGraduation3;
                objdest.CreatedDate                   = objdest.CreatedDate;
                objdest.IsDeleted                     = objdest.IsDeleted;
                objdest.ConferenceAttendedDate        = DateTime.Now.Date;
                objdest.ConferenceAttendedName        = "NA";
                objdest.ConferenceAttendedTitle       = "NA";
                objdest.ProfessionalAssociationsDate  = DateTime.Now.Date;
                objdest.ProfessionalAssociationsIdNo  = "1";
                objdest.ProfessionalAssociationsTitle = "NA";
                objdest.EmployeeGI                    = objempGi;
                db.SaveChanges();
                int i = (from a in db.EmployeeAIs where a.EmployeeCode == obj.EmployeeCode select a).Count();
                if (i == 0)
                {
                    //entities.EmployeeAIs.Add(obj);

                    //Check for NULL.
                    if (ObjAssociation == null)
                    {
                        ObjAssociation = new List <EmpAIAssociation>();
                    }
                }

                //Loop and insert records.
                foreach (EmpAIAssociation item in ObjAssociation)
                {
                    EmpAIAssociation Existed_Emp = db.EmpAIAssociations.Find(item.AssociationsId);
                    Existed_Emp.IDnumber     = item.IDnumber;
                    Existed_Emp.Title        = item.Title;
                    Existed_Emp.AttendedDate = item.AttendedDate;
                    Existed_Emp.IsDeleted    = false;
                }
                db.SaveChanges();

                if (ObjConferenece == null)
                {
                    ObjConferenece = new List <EmpAIConference>();
                }

                //Loop and insert records.
                foreach (EmpAIConference item in ObjConferenece)
                {
                    EmpAIConference Existed_Emp = db.EmpAIConferences.Find(item.ConferenceId);
                    Existed_Emp.Name         = item.Name;
                    Existed_Emp.Title        = item.Title;
                    Existed_Emp.AttendedDate = item.AttendedDate;
                    Existed_Emp.IsDeleted    = false;
                }
                db.SaveChanges();

                insertedRecords = id;
            }

            catch (Exception ext)
            {
            }
            return(Json(insertedRecords));
        }
Exemplo n.º 15
0
        public ActionResult Edit([Bind(Include = "CustomerId,EmployeeGIId,EmployeeCode,Rank,File_No,Grade_Level,Step,Cadre,Title,First_Name,Middle_Name,Surname,Sex,DateOfBirth,PlaceOfBirth,Marital_Status,Maiden_Name,Spouse_Name,StateOfOrigin,LGA,Home_Town,Religion,ContactHomeAddress,FirstAppointmentDate,FirstAppointmentLocation,ConfirmationDate,DateOfRetirement,LastPromotionDate,Programmes,Unit_Services,Unit_Research,Section,LeaveDays,Leave_fromDate,Leave_ToDate,EmployeePhoto,EmployeePhotoImage,StationOfDeployment,IsDeleted,CreatedDate")] EmployeeGI employeeGI)
        {
            try
            {
                //if (ModelState.IsValid)
                //{
                if (employeeGI.EmployeePhotoImage != null && employeeGI.EmployeePhotoImage.ContentLength > 0)
                {
                    var uploadDir = "~/uploads";
                    var imagePath = Path.Combine(Server.MapPath(uploadDir), employeeGI.EmployeePhotoImage.FileName.ToString());
                    var imageUrl  = Path.Combine(uploadDir, employeeGI.EmployeePhotoImage.FileName.ToString());
                    employeeGI.EmployeePhoto = employeeGI.EmployeePhotoImage.FileName.ToString();
                    employeeGI.EmployeePhotoImage.SaveAs(imagePath);
                }
                if (employeeGI.Marital_Status != "Married")
                {
                    employeeGI.Spouse_Name = "N/A";
                }


                employeeGI.Leave_fromDate = DateTime.Now.Date;
                employeeGI.Leave_ToDate   = DateTime.Now.Date;
                TimeSpan daydiff = Convert.ToDateTime(employeeGI.Leave_ToDate) - Convert.ToDateTime(employeeGI.Leave_fromDate);

                employeeGI.LeaveDays       = daydiff.Days;
                employeeGI.CreatedDate     = DateTime.Now.Date;
                employeeGI.IsDeleted       = false;
                db.Entry(employeeGI).State = EntityState.Modified;
                db.SaveChanges();
                TempData["successmsg"] = "Record is Successfully Updated";
                TempData["msg"]        = "";
                int empcode = Convert.ToInt32(@Session["employeecode"]);

                DateTime dttoday  = DateTime.Now.Date;
                var      Role     = (from a in db.UserMasters where a.EmployeeCode == empcode select a.RoleId).FirstOrDefault();
                var      RoleName = (from b in db.RoleMasters where b.RoleId == Role select b.RoleName).FirstOrDefault();
                //if (RoleName == "Admin" || RoleName == "Super Admin")
                //{
                return(RedirectToAction("Index"));
                //}
                //else if (RoleName == "Mid Level Admin")
                //{
                //    return RedirectToAction("MidLevelIndex");
                //}
                //else if (RoleName == "Low Level Admin")
                //{
                //    return RedirectToAction("MidLevelIndex");
                //}
                //else
                //{
                //    return RedirectToAction("UserIndex");
                //}
            }
            catch (Exception ext)
            {
                TempData["successmsg"] = "";

                TempData["msg"] = "Record is not Updated,Try again";
            }
            //}
            //ViewBag.EmployeeCode = new SelectList(db.EmployeeGIs, "EmployeeCode", "EmployeeCode", employeeGI.EmployeeCode);
            return(RedirectToAction("Index"));
        }