public JsonResult DeleteEmployeeInformation(int?id)
 {
     try
     {
         tblEmployeeInformation aEmployee = unitOfWork.EmployeeInformationRepository.GetByID(id);
         if (aEmployee == null)
         {
             return(Json(new { success = false, errorMessage = "Employee Information Delete Failed" }, JsonRequestBehavior.AllowGet));
         }
         unitOfWork.EmployeeInformationRepository.Delete(aEmployee);
         unitOfWork.Save();
         return(Json(new { success = true, message = "Employee Information Deleted successfully" }, JsonRequestBehavior.AllowGet));
     }
     catch (Exception ex)
     {
         return(Json(new { success = false, errorMessage = ex.Message }, JsonRequestBehavior.AllowGet));
     }
 }
        public JsonResult SaveEmployeeInformation(HttpPostedFileBase file, VM_EmployeeInformation aEmployee)
        {
            //string emptyEmail = "undefined";
            var EmailExist = unitOfWork.EmployeeInformationRepository.Get()
                             .Where(a => a.EmployeeEmail == aEmployee.EmployeeEmail && a.EmployeeEmail != "undefined" && a.EmployeeEmail != "").ToList();


            if (ModelState.IsValid)
            {
                try
                {
                    if (!EmailExist.Any())
                    {
                        string path = "";
                        if (file != null)
                        {
                            string pic = System.IO.Path.GetFileName(file.FileName);
                            path = System.IO.Path.Combine(
                                Server.MapPath("~/Image"), pic);
                            // file is uploaded
                            file.SaveAs(path);

                            tblEmployeeInformation employee = new tblEmployeeInformation();
                            employee.EmployeeName    = aEmployee.EmployeeName;
                            employee.EmployeeAddress = aEmployee.EmployeeAddress;
                            employee.ContactNumber   = aEmployee.ContactNumber;
                            employee.EmployeeNid     = aEmployee.EmployeeNid;
                            employee.EmployeeEmail   = aEmployee.EmployeeEmail;
                            employee.EmployeeImage   = "/Image/" + pic;
                            employee.DesignationId   = aEmployee.DesignationId;
                            employee.RestaurantId    = Int32.Parse(SessionManger.RestaurantOfLoggedInUser(Session).ToString());
                            employee.CreatedBy       = SessionManger.LoggedInUser(Session);
                            employee.CreatedDateTime = DateTime.Now;
                            employee.EditedBy        = null;
                            employee.EditedDateTime  = null;
                            unitOfWork.EmployeeInformationRepository.Insert(employee);
                            unitOfWork.Save();
                        }
                        else
                        {
                            tblEmployeeInformation employee = new tblEmployeeInformation();
                            employee.EmployeeName    = aEmployee.EmployeeName;
                            employee.EmployeeAddress = aEmployee.EmployeeAddress;
                            employee.ContactNumber   = aEmployee.ContactNumber;
                            employee.EmployeeNid     = aEmployee.EmployeeNid;
                            employee.EmployeeEmail   = aEmployee.EmployeeEmail;
                            employee.EmployeeImage   = employee.EmployeeImage;
                            employee.DesignationId   = aEmployee.DesignationId;
                            employee.RestaurantId    = Int32.Parse(SessionManger.RestaurantOfLoggedInUser(Session).ToString());
                            employee.CreatedBy       = SessionManger.LoggedInUser(Session);
                            employee.CreatedDateTime = DateTime.Now;
                            employee.EditedBy        = null;
                            employee.EditedDateTime  = null;
                            unitOfWork.EmployeeInformationRepository.Insert(employee);
                            unitOfWork.Save();
                        }
                        return(Json(new { success = true, successMessage = "Employee Information Added Successfully" }));
                    }
                    else
                    {
                        return(Json(new { success = false, errorMessage = "The email already exist" }, JsonRequestBehavior.AllowGet));
                    }
                }
                catch (Exception ex)
                {
                    return(Json(new { success = false, errorMessage = ex.Message }, JsonRequestBehavior.AllowGet));
                }
            }
            else
            {
                return(Json(new { success = false, errorMessage = "Please Fill Up all required field." }, JsonRequestBehavior.AllowGet));
            }
        }
        public JsonResult UpdateEmployeeInformation(HttpPostedFileBase file, VM_EmployeeInformation aEmployee)
        {
            tblEmployeeInformation employeeInformation = unitOfWork.EmployeeInformationRepository.GetByID(aEmployee.EmployeeId);


            string path = "";

            if (file != null)
            {
                string pic = System.IO.Path.GetFileName(file.FileName);
                path = System.IO.Path.Combine(
                    Server.MapPath("~/Image"), pic);
                // file is uploaded
                file.SaveAs(path);

                employeeInformation.EmployeeId      = aEmployee.EmployeeId;
                employeeInformation.EmployeeName    = aEmployee.EmployeeName;
                employeeInformation.EmployeeAddress = aEmployee.EmployeeAddress;
                employeeInformation.ContactNumber   = aEmployee.ContactNumber;
                employeeInformation.EmployeeNid     = aEmployee.EmployeeNid;
                employeeInformation.EmployeeEmail   = aEmployee.EmployeeEmail;
                employeeInformation.EmployeeImage   = "/Image/" + pic;
                employeeInformation.DesignationId   = aEmployee.DesignationId;
                employeeInformation.EditedBy        = SessionManger.LoggedInUser(Session);
                employeeInformation.EditedDateTime  = DateTime.Now;
            }

            else
            {
                employeeInformation.EmployeeId      = aEmployee.EmployeeId;
                employeeInformation.EmployeeName    = aEmployee.EmployeeName;
                employeeInformation.EmployeeAddress = aEmployee.EmployeeAddress;
                employeeInformation.ContactNumber   = aEmployee.ContactNumber;
                employeeInformation.EmployeeNid     = aEmployee.EmployeeNid;
                employeeInformation.EmployeeEmail   = aEmployee.EmployeeEmail;
                employeeInformation.EmployeeImage   = employeeInformation.EmployeeImage;
                employeeInformation.DesignationId   = aEmployee.DesignationId;
                employeeInformation.EditedBy        = SessionManger.LoggedInUser(Session);
                employeeInformation.EditedDateTime  = DateTime.Now;
            }
            var EmailExist = unitOfWork.EmployeeInformationRepository.Get()
                             .Where(a => a.EmployeeEmail == aEmployee.EmployeeEmail && a.EmployeeId != aEmployee.EmployeeId && a.EmployeeEmail != "undefined" && !string.IsNullOrEmpty(a.EmployeeEmail)).ToList();

            try
            {
                if (!EmailExist.Any())
                {
                    unitOfWork.EmployeeInformationRepository.Update(employeeInformation);
                    unitOfWork.Save();
                    return(Json(new { success = true, successMessage = "Successfully Edited" },
                                JsonRequestBehavior.AllowGet));
                }
                else
                {
                    return(Json(new { success = false, errorMessage = "This Email already exist." }, JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception exception)
            {
                return(Json(new { success = false, errorMessage = exception.Message }, JsonRequestBehavior.AllowGet));
            }
        }
        public ActionResult Update(HttpPostedFileBase file, HttpPostedFileBase nidFile, HttpPostedFileBase drivingLicenseFile, VM_EmployeeInformation aEmployee)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    tblEmployeeInformation aEmployeeInformation = unitOfWork.EmployeeInformationRepository.GetByID(aEmployee.EmployeeId);
                    var EmailExist = unitOfWork.EmployeeInformationRepository.Get()
                                     .Where(a => a.EmployeeEmail == aEmployee.EmployeeEmail && a.EmployeeEmail != aEmployeeInformation.EmployeeEmail && a.EmployeeEmail != "undefined" && a.EmployeeEmail != null && a.EmployeeEmail != " " && a.EmployeeEmail != "NULL" && a.EmployeeEmail != "null" && !string.IsNullOrEmpty(a.EmployeeEmail)).ToList();


                    if (!EmailExist.Any())
                    {
                        string path = "";
                        if (file != null)
                        {
                            string pic = System.IO.Path.GetFileName(file.FileName);
                            path = System.IO.Path.Combine(
                                Server.MapPath("~/Image"), pic);
                            // file is uploaded
                            file.SaveAs(path);

                            if (nidFile != null)
                            {
                                string picNid = System.IO.Path.GetFileName(nidFile.FileName);
                                path = System.IO.Path.Combine(
                                    Server.MapPath("~/Image"), picNid);
                                // file is uploaded
                                nidFile.SaveAs(path);

                                if (drivingLicenseFile != null)
                                {
                                    string picDrivingLicense = System.IO.Path.GetFileName(drivingLicenseFile.FileName);
                                    path = System.IO.Path.Combine(
                                        Server.MapPath("~/Image"), picDrivingLicense);
                                    // file is uploaded
                                    drivingLicenseFile.SaveAs(path);


                                    aEmployeeInformation.EmployeeName        = aEmployee.EmployeeName;
                                    aEmployeeInformation.EmployeeAddress     = aEmployee.EmployeeAddress;
                                    aEmployeeInformation.ContactNumber       = aEmployee.ContactNumber;
                                    aEmployeeInformation.EmployeeNid         = aEmployee.EmployeeNid;
                                    aEmployeeInformation.EmployeeNidImage    = "/Image/" + picNid;
                                    aEmployeeInformation.EmployeeEmail       = aEmployee.EmployeeEmail;
                                    aEmployeeInformation.EmployeeImage       = "/Image/" + pic;
                                    aEmployeeInformation.DesignationId       = aEmployee.DesignationId;
                                    aEmployeeInformation.DrivingLicenseImage = "/Image/" + picDrivingLicense;
                                    aEmployeeInformation.Salary         = aEmployee.Salary;
                                    aEmployeeInformation.RouteId        = aEmployee.RouteId;
                                    aEmployeeInformation.EditedBy       = SessionManger.LoggedInUser(Session);
                                    aEmployeeInformation.EditedDateTime = DateTime.Now;

                                    unitOfWork.EmployeeInformationRepository.Update(aEmployeeInformation);
                                    unitOfWork.Save();
                                }
                                else
                                {
                                    aEmployeeInformation.EmployeeName        = aEmployee.EmployeeName;
                                    aEmployeeInformation.EmployeeAddress     = aEmployee.EmployeeAddress;
                                    aEmployeeInformation.ContactNumber       = aEmployee.ContactNumber;
                                    aEmployeeInformation.EmployeeNid         = aEmployee.EmployeeNid;
                                    aEmployeeInformation.EmployeeNidImage    = "/Image/" + picNid;
                                    aEmployeeInformation.EmployeeEmail       = aEmployee.EmployeeEmail;
                                    aEmployeeInformation.EmployeeImage       = "/Image/" + pic;
                                    aEmployeeInformation.DesignationId       = aEmployee.DesignationId;
                                    aEmployeeInformation.DrivingLicenseImage = aEmployee.DrivingLicenseImage;
                                    aEmployeeInformation.Salary         = aEmployee.Salary;
                                    aEmployeeInformation.RouteId        = aEmployee.RouteId;
                                    aEmployeeInformation.EditedBy       = SessionManger.LoggedInUser(Session);
                                    aEmployeeInformation.EditedDateTime = DateTime.Now;

                                    unitOfWork.EmployeeInformationRepository.Update(aEmployeeInformation);
                                    unitOfWork.Save();
                                }
                            }
                            else
                            {
                                if (drivingLicenseFile != null)
                                {
                                    string picDrivingLicense = System.IO.Path.GetFileName(drivingLicenseFile.FileName);
                                    path = System.IO.Path.Combine(
                                        Server.MapPath("~/Image"), picDrivingLicense);
                                    // file is uploaded
                                    drivingLicenseFile.SaveAs(path);

                                    aEmployeeInformation.EmployeeName        = aEmployee.EmployeeName;
                                    aEmployeeInformation.EmployeeAddress     = aEmployee.EmployeeAddress;
                                    aEmployeeInformation.ContactNumber       = aEmployee.ContactNumber;
                                    aEmployeeInformation.EmployeeNid         = aEmployee.EmployeeNid;
                                    aEmployeeInformation.EmployeeNidImage    = aEmployee.EmployeeNidImage;
                                    aEmployeeInformation.EmployeeEmail       = aEmployee.EmployeeEmail;
                                    aEmployeeInformation.EmployeeImage       = "/Image/" + pic;
                                    aEmployeeInformation.DesignationId       = aEmployee.DesignationId;
                                    aEmployeeInformation.DrivingLicenseImage = "/Image/" + picDrivingLicense;
                                    aEmployeeInformation.Salary         = aEmployee.Salary;
                                    aEmployeeInformation.RouteId        = aEmployee.RouteId;
                                    aEmployeeInformation.EditedBy       = SessionManger.LoggedInUser(Session);
                                    aEmployeeInformation.EditedDateTime = DateTime.Now;

                                    unitOfWork.EmployeeInformationRepository.Update(aEmployeeInformation);
                                    unitOfWork.Save();
                                }

                                else
                                {
                                    aEmployeeInformation.EmployeeName        = aEmployee.EmployeeName;
                                    aEmployeeInformation.EmployeeAddress     = aEmployee.EmployeeAddress;
                                    aEmployeeInformation.ContactNumber       = aEmployee.ContactNumber;
                                    aEmployeeInformation.EmployeeNid         = aEmployee.EmployeeNid;
                                    aEmployeeInformation.EmployeeNidImage    = aEmployee.EmployeeNidImage;
                                    aEmployeeInformation.EmployeeEmail       = aEmployee.EmployeeEmail;
                                    aEmployeeInformation.EmployeeImage       = "/Image/" + pic;
                                    aEmployeeInformation.DesignationId       = aEmployee.DesignationId;
                                    aEmployeeInformation.DrivingLicenseImage = aEmployee.DrivingLicenseImage;
                                    aEmployeeInformation.Salary         = aEmployee.Salary;
                                    aEmployeeInformation.RouteId        = aEmployee.RouteId;
                                    aEmployeeInformation.EditedBy       = SessionManger.LoggedInUser(Session);
                                    aEmployeeInformation.EditedDateTime = DateTime.Now;

                                    unitOfWork.EmployeeInformationRepository.Update(aEmployeeInformation);
                                    unitOfWork.Save();
                                }
                            }
                        }
                        else
                        {
                            if (nidFile != null)
                            {
                                string picNid = System.IO.Path.GetFileName(nidFile.FileName);
                                path = System.IO.Path.Combine(
                                    Server.MapPath("~/Image"), picNid);
                                // file is uploaded
                                nidFile.SaveAs(path);

                                if (drivingLicenseFile != null)
                                {
                                    string picDrivingLicense = System.IO.Path.GetFileName(drivingLicenseFile.FileName);
                                    path = System.IO.Path.Combine(
                                        Server.MapPath("~/Image"), picDrivingLicense);
                                    // file is uploaded
                                    drivingLicenseFile.SaveAs(path);

                                    aEmployeeInformation.EmployeeName        = aEmployee.EmployeeName;
                                    aEmployeeInformation.EmployeeAddress     = aEmployee.EmployeeAddress;
                                    aEmployeeInformation.ContactNumber       = aEmployee.ContactNumber;
                                    aEmployeeInformation.EmployeeNid         = aEmployee.EmployeeNid;
                                    aEmployeeInformation.EmployeeNidImage    = "/Image/" + picNid;
                                    aEmployeeInformation.EmployeeEmail       = aEmployee.EmployeeEmail;
                                    aEmployeeInformation.EmployeeImage       = aEmployee.EmployeeImage;
                                    aEmployeeInformation.DesignationId       = aEmployee.DesignationId;
                                    aEmployeeInformation.DrivingLicenseImage = "/Image/" + picDrivingLicense;
                                    aEmployeeInformation.Salary         = aEmployee.Salary;
                                    aEmployeeInformation.RouteId        = aEmployee.RouteId;
                                    aEmployeeInformation.EditedBy       = SessionManger.LoggedInUser(Session);
                                    aEmployeeInformation.EditedDateTime = DateTime.Now;
                                    unitOfWork.EmployeeInformationRepository.Update(aEmployeeInformation);
                                    unitOfWork.Save();
                                }
                                else
                                {
                                    aEmployeeInformation.EmployeeName        = aEmployee.EmployeeName;
                                    aEmployeeInformation.EmployeeAddress     = aEmployee.EmployeeAddress;
                                    aEmployeeInformation.ContactNumber       = aEmployee.ContactNumber;
                                    aEmployeeInformation.EmployeeNid         = aEmployee.EmployeeNid;
                                    aEmployeeInformation.EmployeeNidImage    = "/Image/" + picNid;
                                    aEmployeeInformation.EmployeeEmail       = aEmployee.EmployeeEmail;
                                    aEmployeeInformation.EmployeeImage       = aEmployee.EmployeeImage;
                                    aEmployeeInformation.DesignationId       = aEmployee.DesignationId;
                                    aEmployeeInformation.DrivingLicenseImage = aEmployee.DrivingLicenseImage;
                                    aEmployeeInformation.Salary         = aEmployee.Salary;
                                    aEmployeeInformation.RouteId        = aEmployee.RouteId;
                                    aEmployeeInformation.EditedBy       = SessionManger.LoggedInUser(Session);
                                    aEmployeeInformation.EditedDateTime = DateTime.Now;
                                    unitOfWork.EmployeeInformationRepository.Update(aEmployeeInformation);
                                    unitOfWork.Save();
                                }
                            }
                            else
                            {
                                if (drivingLicenseFile != null)
                                {
                                    string picDrivingLicense = System.IO.Path.GetFileName(drivingLicenseFile.FileName);
                                    path = System.IO.Path.Combine(
                                        Server.MapPath("~/Image"), picDrivingLicense);
                                    // file is uploaded
                                    drivingLicenseFile.SaveAs(path);

                                    aEmployeeInformation.EmployeeName        = aEmployee.EmployeeName;
                                    aEmployeeInformation.EmployeeAddress     = aEmployee.EmployeeAddress;
                                    aEmployeeInformation.ContactNumber       = aEmployee.ContactNumber;
                                    aEmployeeInformation.EmployeeNid         = aEmployee.EmployeeNid;
                                    aEmployeeInformation.EmployeeNidImage    = aEmployee.EmployeeNidImage;
                                    aEmployeeInformation.EmployeeEmail       = aEmployee.EmployeeEmail;
                                    aEmployeeInformation.EmployeeImage       = aEmployee.EmployeeImage;
                                    aEmployeeInformation.DesignationId       = aEmployee.DesignationId;
                                    aEmployeeInformation.DrivingLicenseImage = "/Image/" + picDrivingLicense;
                                    aEmployeeInformation.Salary         = aEmployee.Salary;
                                    aEmployeeInformation.RouteId        = aEmployee.RouteId;
                                    aEmployeeInformation.EditedBy       = SessionManger.LoggedInUser(Session);
                                    aEmployeeInformation.EditedDateTime = DateTime.Now;
                                    unitOfWork.EmployeeInformationRepository.Update(aEmployeeInformation);
                                    unitOfWork.Save();
                                }
                                else
                                {
                                    aEmployeeInformation.EmployeeName        = aEmployee.EmployeeName;
                                    aEmployeeInformation.EmployeeAddress     = aEmployee.EmployeeAddress;
                                    aEmployeeInformation.ContactNumber       = aEmployee.ContactNumber;
                                    aEmployeeInformation.EmployeeNid         = aEmployee.EmployeeNid;
                                    aEmployeeInformation.EmployeeNidImage    = aEmployee.EmployeeNidImage;
                                    aEmployeeInformation.EmployeeEmail       = aEmployee.EmployeeEmail;
                                    aEmployeeInformation.EmployeeImage       = aEmployee.EmployeeImage;
                                    aEmployeeInformation.DesignationId       = aEmployee.DesignationId;
                                    aEmployeeInformation.DrivingLicenseImage = aEmployee.DrivingLicenseImage;
                                    aEmployeeInformation.Salary         = aEmployee.Salary;
                                    aEmployeeInformation.RouteId        = aEmployee.RouteId;
                                    aEmployeeInformation.EditedBy       = SessionManger.LoggedInUser(Session);
                                    aEmployeeInformation.EditedDateTime = DateTime.Now;
                                    unitOfWork.EmployeeInformationRepository.Update(aEmployeeInformation);
                                    unitOfWork.Save();
                                }
                            }
                        }
                        return(Json(new { success = true, successMessage = "Employee Information Update Successfully" }));
                    }
                    else
                    {
                        return(Json(new { success = false, errorMessage = "The email already exist" }, JsonRequestBehavior.AllowGet));
                    }
                }
                catch (Exception ex)
                {
                    return(Json(new { success = false, errorMessage = ex }, JsonRequestBehavior.AllowGet));
                }
            }
            else
            {
                return(Json(new { success = false, errorMessage = "Model Is not valid" }, JsonRequestBehavior.AllowGet));
            }
        }