示例#1
0
 public EmployeeProfile(EmployeeProfileVM viewModel)
 {
     InitializeComponent();
     ViewModel = viewModel;
     DataContext.DataSource = ViewModel;
     DataContext.ResetBindings(false);
     button1.Click += Button1_Click;
 }
        public ActionResult EditEmployee(int id)
        {
            EmployeeProfileVM model;

            using (BankDB bankDB = new BankDB())
            {
                EmployeesDTO employeesDTO = bankDB.Employees.Find(id);

                if (employeesDTO == null)
                {
                    return(Content("Сотрудник не доступен"));
                }

                model = new EmployeeProfileVM(employeesDTO);

                model.positionList = new SelectList(bankDB.EmployeeRoles.ToList(), "id", "Name");
            }

            return(View(model));
        }
        public ActionResult EditEmployee(EmployeeProfileVM model)
        {
            if (!ModelState.IsValid)
            {
                using (BankDB bankDB = new BankDB())
                {
                    model.positionList = new SelectList(bankDB.EmployeeRoles.ToList(), "Id", "Name");

                    return(View(model));
                }
            }

            if (!string.IsNullOrWhiteSpace(model.EmployeePassword))
            {
                if (!model.EmployeePassword.Equals(model.ConfirmPassword))
                {
                    ModelState.AddModelError("errorPass", "Пароли не совпадают");
                    model.EmployeePassword = "";
                    model.ConfirmPassword  = "";

                    return(View(model));
                }
            }

            using (BankDB bankDB = new BankDB())
            {
                TextInfo textInfo = CultureInfo.CurrentCulture.TextInfo;

                int    id    = model.EmployeeId;
                string email = model.EmployeeEmail;
                string phone = model.EmployeePhone;
                string login = model.EmployeeLogin;

                EmployeesDTO employeesDTO = bankDB.Employees.Find(id);

                if (bankDB.Employees.Where(x => x.EmployeeId != id).Any(x => x.EmployeeEmail == email))
                {
                    ModelState.AddModelError("emailExist", $"Адрес {email} занят");

                    return(View(model));
                }
                else if (bankDB.Employees.Where(x => x.EmployeeId != id).Any(x => x.EmployeePhone == phone))
                {
                    ModelState.AddModelError("phoneExist", $"Номер {phone} занят");

                    return(View(model));
                }
                else if (bankDB.Employees.Where(x => x.EmployeeId != id).Any(x => x.EmployeeLogin == login))
                {
                    ModelState.AddModelError("loginExist", $"Логин {login} занят");

                    return(View(model));
                }

                employeesDTO.EmployeeName    = textInfo.ToTitleCase(model.EmployeeName);
                employeesDTO.EmployeeSurname = textInfo.ToTitleCase(model.EmployeeSurname);
                employeesDTO.EmployeeAge     = model.EmployeeAge;
                employeesDTO.EmployeeEmail   = email;
                employeesDTO.EmployeePhone   = phone;
                employeesDTO.EmployeeLogin   = model.EmployeeLogin;

                employeesDTO.EmployeePositionId = model.EmployeePositionId;
                employeesDTO.EmployeeSalary     = model.EmployeeSalary;

                EmployeeRoleDTO employeeRole = bankDB.EmployeeRoles.FirstOrDefault(x => x.Id == model.EmployeePositionId);

                employeesDTO.EmployeePosition = employeeRole.Name;

                if (!string.IsNullOrWhiteSpace(model.EmployeePassword))
                {
                    employeesDTO.EmployeePassword = model.EmployeePassword;
                }

                bankDB.SaveChanges();
            }

            TempData["OK"] = "Профиль отредактирован";

            return(RedirectToAction("Index"));
        }
示例#4
0
        public string Get(int empId, string reqType)
        {
            DanpheHTTPResponse <object> responseData = new DanpheHTTPResponse <object>();

            try
            {
                //for employeeprofile, get current employeeinformation, fill the employeeProfileVM object and return to the client.
                if (reqType == "employeeProfile")
                {
                    MasterDbContext masterDbContext = new MasterDbContext(connString);
                    EmployeeModel   currEmp         = (from e in masterDbContext.Employees.Include("Department")
                                                       where e.EmployeeId == empId
                                                       select e).FirstOrDefault();
                    RbacUser currUser = (from u in (new RbacDbContext(connString)).Users
                                         where u.EmployeeId == empId
                                         select u).FirstOrDefault();

                    EmployeeProfileVM empProfile = new EmployeeProfileVM();
                    empProfile.EmployeeId = currEmp.EmployeeId;
                    empProfile.FirstName  = currEmp.FirstName;
                    empProfile.LastName   = currEmp.LastName;
                    empProfile.UserName   = currUser != null ? currUser.UserName : "******";
                    //sometimes department could also be null, so handling such cases accordingly.
                    empProfile.Department    = currEmp.Department != null ? currEmp.Department.DepartmentName : "not assigned";
                    empProfile.DateOfBirth   = currEmp.DateOfBirth;
                    empProfile.DateOfJoining = currEmp.DateOfJoining;
                    empProfile.ImageName     = currEmp.ImageName;
                    empProfile.Email         = currEmp.Email;
                    empProfile.ContactNumber = currEmp.ContactNumber;
                    empProfile.ImageFullPath = string.IsNullOrEmpty(currEmp.ImageName) ? "" : fileUploadLocation + "UserProfile\\" + currEmp.ImageName;

                    responseData.Results = empProfile;
                    responseData.Status  = "OK";
                }


                else
                {
                    responseData.Status       = "Failed";
                    responseData.ErrorMessage = "Invalid request type.";
                }
                //else
                //{

                //    RbacDbContext rbacDbContext = new RbacDbContext(connString);
                //    MasterDbContext masterDbContext = new MasterDbContext(connString);

                //    RbacUser currUser = rbacDbContext.Users.Where(u => u.UserId == empId).FirstOrDefault();
                //    var UserProfileInfo = (from x in masterDbContext.Employee
                //                           where x.EmployeeId == currUser.EmployeeId
                //                           select new
                //                           {
                //                               UserName = currUser.UserName,
                //                               FirstName = x.FirstName,
                //                               LastName = x.LastName,
                //                               Email = x.Email,
                //                               Department = x.EmployeeDepartment,
                //                               EmployeeId = x.EmployeeId,
                //                               ImageName = x.ImageName
                //                           }).ToList();

                //    responseData.Results = UserProfileInfo;
                //    responseData.Status = "OK";
                //}
            }
            catch (Exception ex)
            {
                responseData.Status       = "Failed";
                responseData.ErrorMessage = ex.Message + " exception details:" + ex.ToString();
            }
            return(DanpheJSONConvert.SerializeObject(responseData, true));
        }