public ActionResult EditEmployee(int id)
        {
            if (Convert.ToInt32(Session["UserType"]) > 2 || Session["UserID"] == null)
            {
                return(this.Redirect(Url.Action("Index", "Home")));
            }
            CRUDService.ServiceClient sr = new CRUDService.ServiceClient();
            cEmployee client             = sr.getEmployee(id);

            return(View(client));
        }
        public ActionResult ChangeEmployee(cEmployee client)
        {
            if (Session["UserID"] == null)
            {
                return(this.Redirect(Url.Action("Index", "Home")));
            }

            CRUDService.ServiceClient sr = new CRUDService.ServiceClient();
            bool isEditied = sr.editEmployee(client);

            if (isEditied)
            {
                return(View());
            }
            else
            {
                return(this.Redirect(Url.Action("EditEmployee", "Management")));
            }
        }
Ejemplo n.º 3
0
        public JsonResult Add(EmployeeViewModel emp, string hdnEmployeeID)
        {
            try
            {
                EmployeeViewModel objEmpViewMod = new EmployeeViewModel();
                if (emp.SelectedRollAccess[0] == "" || emp.SelectedReportHead[0] == "" || emp.SelectedLocation[0] == "" || emp.SelectedDepartmentType[0] == "" || emp.SelectedDesignation[0] == "" || emp.SelectedRollAccess[0] == "" || emp.SelectedReportHead[0] == "")
                {
                    return(Json("1"));//Some Dropdown are not selected
                }
                else
                {
                    //if (ModelState.IsValid)
                    //{
                    if (hdnEmployeeID != null && hdnEmployeeID != "")
                    {
                        string strTitle = "0";
                        if (emp.SelectedTitle[0] == "")
                        {
                            strTitle = "0";
                        }
                        else
                        {
                            strTitle = emp.SelectedTitle[0];
                        }
                        int ID = Convert.ToInt32(hdnEmployeeID);

                        cEmpLogin objEmpLogin = cEmpLogin.Get_ID(ID);
                        objEmpLogin.sEmailID = emp.EmployeeEmailIdUpdate;
                        List <cManageGroup> objManag = cManageGroup.Find(" objFunctionalGroup = " + emp.DepTypeID + " and iReportingHead = " + Convert.ToInt32(emp.SelectedReportHead[0]));
                        if (objManag.Count > 0)
                        {
                            objEmpLogin.objManageGroup.iObjectID = objManag[0].iID;
                        }
                        else
                        {
                            cManageGroup aobjManag = cManageGroup.Create();
                            aobjManag.objFunctionalGroup.iObjectID = Convert.ToInt32(emp.SelectedDepartmentType[0]);
                            aobjManag.iReportingHead = Convert.ToInt32(emp.SelectedReportHead[0]);
                            aobjManag.Save();
                            objEmpLogin.objManageGroup.iObjectID = aobjManag.iID;
                        }
                        objEmpLogin.objRoleAccess.iObjectID  = Convert.ToInt32(emp.SelectedRollAccess[0]);
                        objEmpLogin.objTitle.iObjectID       = Convert.ToInt32(emp.SelectedTitle[0]);
                        objEmpLogin.objLocation.iObjectID    = Convert.ToInt32(emp.SelectedLocation[0]);
                        objEmpLogin.objDesignation.iObjectID = Convert.ToInt32(emp.SelectedDesignation[0]);
                        objEmpLogin.sFirstTime = "1";
                        objEmpLogin.bIsActive  = true;
                        objEmpLogin.sPassword  = emp.Password;
                        objEmpLogin.Save();

                        List <cEmpPersonalDetails> aobjEmployeePersonalDetails = cEmpPersonalDetails.Find(" objEmpLogin = "******"";
                        }
                        else
                        {
                            aobjEmployeePersonalDetails[0].sMiddleName = aobjEmployeePersonalDetails[0].sMiddleName;
                        }
                        //aobjEmployeePersonalDetails[0].sMiddleName = emp.EmpPersonal.MiddleName;

                        aobjEmployeePersonalDetails[0].sLastName             = emp.EmpPersonal.LastName;
                        aobjEmployeePersonalDetails[0].sPersoanlEmailID      = emp.PersonalEmailUpdate;
                        aobjEmployeePersonalDetails[0].objEmpLogin.iObjectID = objEmpLogin.iID;
                        aobjEmployeePersonalDetails[0].Save();


                        List <cEmployee> aobjEmp = cEmployee.Find(" objEmpLogin = "******" iID = " + aobjEmp[0].objEmpDesigDepartmentType.iObjectID);
                        //aobjDesigDepart[0].objDepartmentType.iObjectID = Convert.ToInt32(emp.SelectedDepartmentType[0]);
                        //aobjDesigDepart[0].objDesignation.iObjectID = Convert.ToInt32(emp.SelectedDesignation[0]);
                        //aobjDesigDepart[0].Save();
                        MailCreateEmployee(objEmpLogin.sEmailID, objEmpLogin.sPassword, "Update");
                        return(Json("2"));//Update
                    }
                    else
                    {
                        string strTitle = "0";
                        if (emp.SelectedTitle[0] == "")
                        {
                            strTitle = "0";
                        }
                        else
                        {
                            strTitle = emp.SelectedTitle[0];
                        }
                        cEmpLogin objEmpLogin = cEmpLogin.Create();
                        objEmpLogin.sEmailID = emp.EmployeeEmailId;
                        objEmpLogin.objRoleAccess.iObjectID = Convert.ToInt32(emp.SelectedRollAccess[0]);
                        objEmpLogin.sFirstTime = "1";
                        objEmpLogin.bIsActive  = true;
                        objEmpLogin.sPassword  = emp.Password;
                        objEmpLogin.objDesignation.iObjectID = Convert.ToInt32(emp.SelectedDesignation[0]);
                        objEmpLogin.objLocation.iObjectID    = Convert.ToInt32(emp.SelectedLocation[0]);
                        objEmpLogin.objTitle.iObjectID       = Convert.ToInt32(emp.SelectedTitle[0]);
                        List <cManageGroup> objManag = cManageGroup.Find(" objFunctionalGroup = " + emp.DepTypeID + " and iReportingHead = " + Convert.ToInt32(emp.SelectedReportHead[0]));
                        if (objManag.Count > 0)
                        {
                            objEmpLogin.objManageGroup.iObjectID = objManag[0].iID;
                        }
                        else
                        {
                            cManageGroup aobjManag = cManageGroup.Create();
                            aobjManag.objFunctionalGroup.iObjectID = Convert.ToInt32(emp.SelectedDepartmentType[0]);
                            aobjManag.iReportingHead = Convert.ToInt32(emp.SelectedReportHead[0]);
                            aobjManag.Save();
                            objEmpLogin.objManageGroup.iObjectID = aobjManag.iID;
                        }
                        objEmpLogin.Save();

                        cEmpPersonalDetails objEmployeePersonalDetails = cEmpPersonalDetails.Create();
                        objEmployeePersonalDetails.sFirstName = emp.EmpPersonal.FirstName;
                        if (emp.EmpPersonal.MiddleName == null)
                        {
                            objEmployeePersonalDetails.sMiddleName = "";
                        }
                        else
                        {
                            objEmployeePersonalDetails.sMiddleName = emp.EmpPersonal.MiddleName;
                        }

                        objEmployeePersonalDetails.sLastName             = emp.EmpPersonal.LastName;
                        objEmployeePersonalDetails.sPersoanlEmailID      = emp.PersonalEmail;
                        objEmployeePersonalDetails.objEmpLogin.iObjectID = objEmpLogin.iID;
                        objEmployeePersonalDetails.bIsActive             = true;
                        objEmployeePersonalDetails.Save();

                        cEmployee objEmp = cEmployee.Create();
                        objEmp.objEmpLogin.iObjectID = objEmpLogin.iID;

                        objEmp.dtDOJ = Convert.ToDateTime(emp.Employee.DOJ);
                        objEmp.Save();
                        MailCreateEmployee(objEmpLogin.sEmailID, objEmpLogin.sPassword, "Create");
                        return(Json("3"));//Create
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }