public ActionResult AdminLogin(string returnUrl, FormCollection fc)

        {
            if (!string.IsNullOrEmpty(fc["EmployeeCode"]) && !string.IsNullOrEmpty(fc["Password"]))
            {
                var sa = db.SuperAdmins.Find(1);
                if (sa.LoginName.Equals(fc["EmployeeCode"]) && sa.Password.Equals(fc["Password"]))
                {
                    FormsAuthentication.SetAuthCookie(sa.LoginName, true);
                    return(RedirectToAction("Dashboard", "SuperAdmin"));
                }
                int        empCode  = 0; int.TryParse(fc["EmployeeCode"], out empCode);
                string     password = fc["Password"];
                UserMaster user     = db.UserMasters.Where(u => u.EmployeeCode == empCode && u.Password.Equals(password)).FirstOrDefault();
                if (user != null)
                {
                    TempData["wel"] = "Your Login is Successful";
                    {
                        var userName  = user.EmployeeCode.ToString();
                        var empdetail = (from a in db.EmployeeGIs where a.EmployeeCode == user.EmployeeCode select new { empic = a.EmployeePhoto, empname = a.First_Name }).FirstOrDefault();
                        Session["name"]         = empdetail.empname;
                        Session["employeecode"] = user.EmployeeCode.ToString();
                        Session["User"]         = user;

                        Session.Timeout = 60000;
                        string roletext = (from a in db.RoleMasters where a.RoleId == user.RoleId select a.RoleName).FirstOrDefault();
                        var    role     = (from a in db.UserMasters where a.EmployeeCode == user.EmployeeCode select a.RoleId).FirstOrDefault();
                        var    userType = (from a in db.RoleMasters where a.RoleId == role select a.RoleName).FirstOrDefault();
                        Session["Role"] = userType;
                        try
                        {
                            if (userType.Contains("Admin"))
                            {
                                EmployeeAttendance attendence = new EmployeeAttendance();
                                attendence.EmployeeCode = user.EmployeeCode;
                                attendence.OnDate       = Convert.ToDateTime(DateTime.Now.ToShortDateString());
                                string timelogin = String.Format("{0:T}", DateTime.Now);
                                attendence.LoginTime  = Convert.ToDateTime(timelogin); // "4:05 PM";
                                attendence.LogoutTime = Convert.ToDateTime(timelogin);
                                db.EmployeeAttendances.Add(attendence);
                                db.SaveChanges();
                            }
                        }
                        catch { }
                        FormsAuthentication.SetAuthCookie(userName, true);
                        return(RedirectToAction("index", "Home"));
                    }
                }
                else
                {
                    TempData["wel"] = "Invalid UserName or Password";
                    return(RedirectToAction("index", "Login"));
                }
            }
            // else
            {
                TempData["wel"] = "Pls Enter UserName and Password";
                return(RedirectToAction("index", "Login"));
            }
        }
        public ActionResult Create([Bind(Include = "ClassNumber, ClassName, ClassStatus")] ClassMaster classMaster)
        {
            ClassMaster cls = new ClassMaster();

            if (ModelState.IsValid)
            {
                cls.EmployeeID  = Convert.ToInt32(@Session["employeecode"]);
                cls.ClassName   = classMaster.ClassName;
                cls.ClassNumber = classMaster.ClassNumber;
                cls.ClassStatus = classMaster.ClassStatus;
                cls.CreatedDate = DateTime.Now;
                db.ClassMasters.Add(cls);
                db.SaveChanges();
            }
            return(RedirectToAction("Create"));
        }
        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));
        }
        public ActionResult Create([Bind(Include = "CustomerId,StoreNumber,StoreName,StoreStatus,StoreDesc,StoreImgName")] StoreMaster storeMaster, HttpPostedFileBase StoreImgName)
        {
            StoreMaster s = new StoreMaster();

            ViewBag.Status = new SelectList(db.StatusMasters, "RecordId", "StatusName");
            if (StoreImgName != null)
            {
                string path = Server.MapPath("~/Uploads/");
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                System.Drawing.Image img = System.Drawing.Image.FromStream(StoreImgName.InputStream);
                int     height           = img.Height;
                int     width            = img.Width;
                decimal size             = Math.Round(((decimal)StoreImgName.ContentLength / (decimal)1024), 2);

                if (width == 300 || height == 250)
                {
                    s.EmployeeID   = Convert.ToInt32(@Session["employeecode"]);
                    s.CreatedDate  = DateTime.Now;
                    s.StoreName    = storeMaster.StoreName;
                    s.StoreNumber  = storeMaster.StoreNumber;
                    s.StoreStatus  = storeMaster.StoreStatus;
                    s.StoreImgName = (storeMaster.StoreName + "_" + Path.GetFileName(StoreImgName.FileName));
                    s.StoreDesc    = storeMaster.StoreDesc;
                    db.StoreMasters.Add(s);
                    db.SaveChanges();
                    StoreImgName.SaveAs(path + (storeMaster.StoreName + "_" + Path.GetFileName(StoreImgName.FileName)));
                    return(RedirectToAction("Create"));
                }
                else
                {
                    ViewBag.ImgMessage = string.Format("Please Select Image With resolution of 300px X 250px .\\nCurrent resolution is Width: {0}px and Heigth: {1}px", width.ToString(), height.ToString());
                    return(View());
                }
            }
            else
            {
                ViewBag.ImgMessage = string.Format("Please select image");
                return(View());
            }
        }
Example #5
0
        public ActionResult Create([Bind(Include = "CustomerId,UOMName, UOMCode, UOMDesc, UOMStatus")] UomMaster uomMaster)
        {
            UomMaster uom = new UomMaster();

            {
                ModelState.Remove("EmployeeID");
                if (ModelState.IsValid)
                {
                    uom.EmployeeID = Convert.ToInt32(@Session["employeecode"]);
                }
                uom.UOMName     = uomMaster.UOMName;
                uom.UOMDesc     = uomMaster.UOMDesc;
                uom.UOMStatus   = uomMaster.UOMStatus;
                uom.UOMCode     = uomMaster.UOMCode;
                uom.CreatedDate = DateTime.Now;
                db.UomMasters.Add(uom);
                db.SaveChanges();
            }
            return(RedirectToAction("Create"));
        }
        //[ValidateAntiForgeryToken]
        public ActionResult UserCreate([Bind(Include = "CustomerId,LeaveAccId,EmployeeCode,LeaveTypeName,LeaveFromDate,LeaveToDate,NoOfDays,AppDate,IsApproved,IsDeleted,CreatedDate")] LeaveApplication leaveApplication)
        {
            List <LeaveTypeMaster> LeaveTypeklist = new List <LeaveTypeMaster>();

            LeaveTypeklist = (from a in db.LeaveTypeMasters select a).ToList();

            //ViewBag.CountryList = CountryList;
            ViewBag.LeaveTypeName = new SelectList(LeaveTypeklist, "LeaveTypeId", "LeaveTypeName");
            if (ModelState.IsValid)
            {
                int lt        = Convert.ToInt32(leaveApplication.LeaveTypeName);
                var leavetype = (from a in db.LeaveTypeMasters where a.LeaveTypeId == lt select a.LeaveTypeName).FirstOrDefault();
                leaveApplication.LeaveTypeName = leavetype;
                var inprocess = (from a in db.LeaveApplications where a.Status == "Pending" && a.EmployeeCode == leaveApplication.EmployeeCode select a).Count();
                if (inprocess == 0)
                {
                    leaveApplication.Status = "Pending";
                    int count        = (from a in db.LeaveLedgers where a.EmployeeCode == leaveApplication.EmployeeCode && a.LeaveType == leaveApplication.LeaveTypeName select a.BalanceLeaves).Count();
                    var balanceLeave = (from a in db.LeaveLedgers where a.EmployeeCode == leaveApplication.EmployeeCode && a.LeaveType == leaveApplication.LeaveTypeName && a.BalanceLeaves >= leaveApplication.NoOfDays select a.BalanceLeaves).FirstOrDefault();
                    if ((balanceLeave > 0) || (count == 0))
                    {
                        db.LeaveApplications.Add(leaveApplication);
                        db.SaveChanges();
                        TempData["msg"] = "<script>alert('Your Leave Application is Submitted');</script>";
                        return(RedirectToAction("UserIndex"));
                    }
                    else
                    {
                        TempData["msg"] = "<script>alert('No Leaves in Balance');</script>";
                        return(View(leaveApplication));
                    }
                }
                else
                {
                    TempData["msg"] = "<script>alert('Your Application is already in process');</script>";
                }
            }

            return(View(leaveApplication));
        }
        public ActionResult Create([Bind(Include = "CustomerId,OrderNo, VendorId, ItemId,ItemQunt,ItemDesc,ItemTax,DeliLoc,Terms")] PurchaseOrder porder)
        {
            PurchaseOrder po = new PurchaseOrder();

            ModelState.Remove("EmployeeID");
            if (ModelState.IsValid)
            {
                po.OrderNo     = porder.OrderNo;
                po.VendorId    = porder.VendorId;
                po.ItemId      = porder.ItemId;
                po.ItemQunt    = porder.ItemQunt;
                po.ItemDesc    = porder.ItemDesc;
                po.ItemTax     = porder.ItemTax;
                po.DeliLoc     = porder.DeliLoc;
                po.Terms       = porder.Terms;
                po.EmployeeID  = Convert.ToInt32(@Session["employeecode"]);
                po.CreatedDate = DateTime.Now;
                db.PurchaseOrders.Add(po);
                db.SaveChanges();
            }
            return(RedirectToAction("Create"));
        }
Example #8
0
        public JsonResult InsertCriv(List <CrivVoucher> criv)
        {
            using (db)
            {
                if (criv == null)
                {
                    criv = new List <CrivVoucher>();
                }

                //Loop and insert records.
                foreach (CrivVoucher c in criv)
                {
                    CrivVoucher cr = new CrivVoucher();
                    cr.CRIVVoucherId      = c.CRIVVoucherId;
                    cr.EmployeeID         = Convert.ToInt32(@Session["employeecode"]);
                    cr.DepartmentId       = c.DepartmentId;
                    cr.Store              = c.Store;
                    cr.DateIns            = c.DateIns;
                    cr.Item               = c.Item;
                    cr.Class              = c.Class;
                    cr.Qunatity           = c.Qunatity;
                    cr.Uom                = c.Uom;
                    cr.Rate               = c.Rate;
                    cr.TotalValue         = c.TotalValue;
                    cr.BatchDetail        = c.BatchDetail;
                    cr.RequisitionOfficer = c.RequisitionOfficer;
                    cr.RecivingPerson     = c.RecivingPerson;
                    cr.Remarks            = c.Remarks;
                    cr.CreatedDate        = DateTime.Now;
                    cr.TotalCost          = c.TotalCost;
                    cr.AmtWord            = c.AmtWord;
                    cr.Name1              = c.Name1;
                    cr.Fac1               = c.Fac1;
                    cr.Sign1              = c.Sign1;
                    cr.Date1              = c.Date1;
                    cr.Sign2              = c.Sign2;
                    cr.Date2              = c.Date2;
                    cr.Name3              = c.Name3;
                    cr.Fac3               = c.Fac3;
                    cr.Date3              = c.Date3;
                    db.CrivVouchers.Add(cr);
                }
                int insertedRecords = db.SaveChanges();
                insertedRecords = 0;
                return(Json(insertedRecords));
            }
        }
        public ActionResult MidLevelCreate([Bind(Include = "CustomerId,EmployeeMIId,EmployeeCode,NhisNo,NhisProvider,BloodGroup,BloodGenotype,CreatedDate,IsDeleted")] EmployeeMI employeeMI)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    int empidcount = (from a in db.EmployeeMIs where a.EmployeeCode == employeeMI.EmployeeCode select a).Count();
                    if (empidcount == 0)
                    {
                        employeeMI.IsDeleted   = false;
                        employeeMI.CreatedDate = DateTime.Now.Date;
                        db.EmployeeMIs.Add(employeeMI);
                        db.SaveChanges();

                        TempData["successmsg"] = "Record is Successfully Added";
                        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();
                        return(RedirectToAction("MidLevelIndex"));
                        //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", employeeMI.EmployeeCode);
            return(View(employeeMI));
        }
        public JsonResult InsertCustomers(EmployeeAI obj, List <EmpAIAssociation> ObjAssociation, List <EmpAIConference> ObjConferenece)
        {
            int insertedRecords = 0;

            try
            {
                using (IARTDBNEWEntities entities = new IARTDBNEWEntities())
                {
                    int i = (from a in entities.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)
                    {
                        entities.EmpAIAssociations.Add(item);
                    }


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

                    //Loop and insert records.
                    foreach (EmpAIConference item in ObjConferenece)
                    {
                        entities.EmpAIConferences.Add(item);
                    }

                    insertedRecords = entities.SaveChanges();
                }
            }
            catch (Exception ext)
            {
            }
            return(Json(insertedRecords));
        }
        public JsonResult InsertStoreRecipt(List <StoreReciptVoucher> criv)
        {
            using (db)
            {
                if (criv == null)
                {
                    criv = new List <StoreReciptVoucher>();
                }

                //Loop and insert records.
                foreach (StoreReciptVoucher c in criv)
                {
                    StoreReciptVoucher cr = new StoreReciptVoucher();
                    cr.VoucherId      = c.VoucherId;
                    cr.EmployeeID     = Convert.ToInt32(@Session["employeecode"]);
                    cr.DepartmentId   = c.DepartmentId;
                    cr.Store          = c.Store;
                    cr.DateIns        = c.DateIns;
                    cr.Item           = c.Item;
                    cr.Vendor         = c.Vendor;
                    cr.Qunatity       = c.Qunatity;
                    cr.Uom            = c.Uom;
                    cr.Rate           = c.Rate;
                    cr.TotalValue     = c.TotalValue;
                    cr.BatchDetail    = c.BatchDetail;
                    cr.StoreOfficer   = c.StoreOfficer;
                    cr.RecivingPerson = c.RecivingPerson;
                    cr.Remark         = c.Remark;
                    cr.CreatedDate    = DateTime.Now;
                    cr.Date1          = c.Date1;
                    cr.Sign1          = c.Sign1;
                    cr.Date2          = c.Date2;
                    cr.Sign2          = c.Sign2;
                    cr.Date3          = c.Date3;
                    cr.Sign3          = c.Sign3;
                    cr.ReceviedFrom   = c.ReceviedFrom;

                    db.StoreReciptVouchers.Add(cr);
                }
                int insertedRecords = db.SaveChanges();
                insertedRecords = 0;
                return(Json(insertedRecords));
            }
        }
Example #12
0
        public ActionResult Create([Bind(Include = "CustomerId,EmployeePIId,EmployeeCode,EmpEmailId,PermanentAddress,MobileNo,EmailIdKin,KinName,AddressNextOfKin,StateNextOfKin,LGAextOfKin,Relation,PhoneNoNextOfKin,NameOfStaffBenificiary,PhoneOfStaffBenificiary,AddressOfStaffBenificiary,EmployeeStatus,CreatedDate,IsDeleted")] EmployeePI employeePI)
        {
            var user = (UserMaster)Session["User"];
            List <CityMaster> CityList = new List <CityMaster>();

            CityList             = (from CityName in db.CityMasters select CityName).ToList();
            ViewBag.LGAextOfKins = new SelectList(CityList, "City", "City");
            List <StateMaster> StateList = new List <StateMaster>();

            StateList = (from State in db.StateMasters select State).ToList();
            ViewBag.StateNextOfKins = new SelectList(StateList, "State", "State");
            ViewBag.EmployeeCode    = new SelectList(db.EmployeeGIs, "EmployeeCode", "EmployeeCode");
            var isAlready = (from a in db.EmployeePIs where a.EmployeeCode == employeePI.EmployeeCode select a.EmployeeCode).Count();

            if (isAlready == 0)
            {
                try
                {
                    if (ModelState.IsValid)
                    {
                        int empidcount = (from a in db.EmployeePIs where a.EmployeeCode == employeePI.EmployeeCode select a).Count();
                        if (empidcount == 0)
                        {
                            int DuplicateEmailMobile = (from a in db.EmployeePIs where a.EmpEmailId == employeePI.EmpEmailId && a.MobileNo == employeePI.MobileNo select a).ToList().Count();
                            if (DuplicateEmailMobile == 0)
                            {
                                employeePI.CreatedDate = DateTime.Now.Date;
                                db.EmployeePIs.Add(employeePI);
                                db.SaveChanges();
                                TempData["successmsg"] = "Record is Successfully Added";
                                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"));
                                }
                            }
                            else
                            {
                                TempData["msg"] = "Email Id or Mobile No. is already exist";
                                return(View(employeePI));
                            }
                        }
                    }
                }
                catch (Exception ext)
                {
                    TempData["successmsg"] = "";
                    TempData["msg"]        = "Record is not Added,Please try again";
                }

                ViewBag.EmployeeCode = new SelectList(db.EmployeeGIs, "EmployeeCode", "EmployeeCode", employeePI.EmployeeCode);
                return(View(employeePI));
            }
            else
            {
                TempData["successmsg"] = "";
                TempData["msg"]        = "This Record is Already Exist";
                return(View(employeePI));
            }
        }
Example #13
0
        public ActionResult Create([Bind(Include = "CustomerId,StoreId, ClassId, ItemName,ItemCat,UomId,VendorId,ItemRate,ItemTax,StatusId,ItemDesc")] ItemMaster item, HttpPostedFileBase ItemImage)
        {
            ItemMaster i = new ItemMaster();

            ModelState.Remove("ItemImage");
            if (ModelState.IsValid)
            {
                if (ItemImage != null)
                {
                    string path = Server.MapPath("~/Uploads/");
                    if (!Directory.Exists(path))
                    {
                        Directory.CreateDirectory(path);
                    }
                    System.Drawing.Image img = System.Drawing.Image.FromStream(ItemImage.InputStream);
                    int     height           = img.Height;
                    int     width            = img.Width;
                    decimal size             = Math.Round(((decimal)ItemImage.ContentLength / (decimal)1024), 2);

                    if (width == 300 || height == 250)
                    {
                        i.EmployeeID  = Convert.ToInt32(@Session["employeecode"]);
                        i.StoreId     = item.StoreId;
                        i.ClassId     = item.ClassId;
                        i.ItemName    = item.ItemName;
                        i.ItemCat     = item.ItemCat;
                        i.UomId       = item.UomId;
                        i.VendorId    = item.VendorId;
                        i.ItemRate    = item.ItemRate;
                        i.ItemTax     = item.ItemTax;
                        i.StatusId    = item.StatusId;
                        i.ItemDesc    = item.ItemDesc;
                        i.ItemImage   = (item.ItemName + "_" + Path.GetFileName(ItemImage.FileName));
                        i.CreatedDate = DateTime.Now;
                        db.ItemMasters.Add(i);
                        db.SaveChanges();
                        ItemImage.SaveAs(path + (item.ItemName + "_" + Path.GetFileName(ItemImage.FileName)));
                        return(RedirectToAction("Create"));
                    }
                    else
                    {
                        ViewBag.Store      = new SelectList(GetStore(), "Value", "Text");
                        ViewBag.Class      = new SelectList(GetClass(), "Value", "Text");
                        ViewBag.Uom        = new SelectList(GetUom(), "Value", "Text");
                        ViewBag.Vendor     = new SelectList(GetVendor(), "Value", "Text");
                        ViewBag.Status     = new SelectList(GetStatus(), "Value", "Text");
                        ViewBag.ImgMessage = string.Format("Please Select Image With resolution of 300px X 250px .\\nCurrent resolution is Width: {0}px and Heigth: {1}px", width.ToString(), height.ToString());
                        return(View());
                    }
                }
                else
                {
                    ViewBag.Store      = new SelectList(GetStore(), "Value", "Text");
                    ViewBag.Class      = new SelectList(GetClass(), "Value", "Text");
                    ViewBag.Uom        = new SelectList(GetUom(), "Value", "Text");
                    ViewBag.Vendor     = new SelectList(GetVendor(), "Value", "Text");
                    ViewBag.Status     = new SelectList(GetStatus(), "Value", "Text");
                    ViewBag.ImgMessage = string.Format("Please select image");
                    return(View());
                }
            }
            return(RedirectToAction("Create"));
        }
        //[ValidateAntiForgeryToken]
        public ActionResult Create([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)
        {
            var isAlready = (from a in db.EmployeeGIs where a.EmployeeCode == employeeGI.EmployeeCode select a.EmployeeCode).Count();

            if (isAlready == 0)
            {
                try
                {
                    if (employeeGI.Marital_Status != "Married")
                    {
                        employeeGI.Spouse_Name = "N/A";
                    }
                    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 (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);
                    }
                    var user = (UserMaster)Session["User"];
                    employeeGI.File_No      = employeeGI.File_No;
                    employeeGI.EmployeeGIId = employeeGI.EmployeeCode;
                    employeeGI.CustomerId   = user.CustomerId;
                    db.EmployeeGIs.Add(employeeGI);
                    db.SaveChanges();
                    TempData["successmsg"] = "Record is Successfully added";
                    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();
                    return(RedirectToAction("Index"));
                }
                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));
            }
            else
            {
                TempData["successmsg"] = "";
                TempData["msg"]        = "This Employee Record is already exist";
                return(View(employeeGI));
            }
        }
        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));
        }