Exemplo n.º 1
0
        public async Task <IActionResult> Edit(string id)
        {
            if (id == null)
            {
                return(RedirectToAction("Error", "Home"));
            }

            EmployeeDetailsServiceModel employee = await this._employeeServices.GetEmployeeByIdAsync(id);

            if (employee == null)
            {
                return(NotFound());
            }

            EmployeeEditBindingModel model = new EmployeeEditBindingModel()
            {
                Id               = employee.EmployeeId,
                FirstName        = employee.FirstName,
                LastName         = employee.LastName,
                StartingDate     = employee.StartingDate,
                Salary           = employee.Salary,
                ExperienceLevel  = employee.ExperienceLevel,
                VacationDays     = employee.VacationDays,
                EmployeesOffices = employee.EmployeesOffices
            };

            return(View(model));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Edit(EmployeeEditBindingModel model)
        {
            if (ModelState.IsValid)
            {
                EmployeeEditServiceModel employeeEditServiceModel = new EmployeeEditServiceModel()
                {
                    Id              = model.Id,
                    FirstName       = model.FirstName,
                    LastName        = model.LastName,
                    StartingDate    = model.StartingDate,
                    Salary          = model.Salary,
                    ExperienceLevel = model.ExperienceLevel,
                    VacationDays    = model.VacationDays,
                };

                bool result = await this._employeeServices.UpdateAsync(employeeEditServiceModel);

                if (!result)
                {
                    return(RedirectToAction("Error", "Home"));
                }

                return(RedirectToAction("Details", new { id = model.Id }));
            }

            return(View(model));
        }
        public async Task <IActionResult> Edit(EmployeeEditBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                return(this.Redirect(string.Format(WebConstants.AdminEmployeesEdit, model.Id)));
            }

            var result = await this.employeesService.UpdateEmployeeByIdAsync(
                model.Id,
                model.FirstName,
                model.LastName,
                model.Email,
                model.PhoneNumber,
                model.DepartmentId,
                model.Password,
                model.RecruitedOn);

            if (!result)
            {
                this.ShowNotification(NotificationMessages.InvalidOperation
                                      , NotificationType.Error);
                return(this.Redirect(WebConstants.HomeIndex));
            }

            this.ShowNotification(NotificationMessages.EmployeeEditSuccessfull,
                                  NotificationType.Success);

            return(this.Redirect(string.Format(WebConstants.AdminEmployeesDetails, model.Id)));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Edit(EmployeeEditBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            var employee = await this.employeesSecrvice.EditEmployeeAsync(model);

            return(this.RedirectToAction("Details", new { id = employee.EmployeeId }));
        }
        public async Task <Employee> EditEmployeeAsync(EmployeeEditBindingModel model)
        {
            var dbEmployee = this.DbContext.Employees.Find(model.EmployeeId);

            dbEmployee.CompanyId         = model.CompanyId;
            dbEmployee.ExperienceLevelId = model.ExperienceLevelId;
            dbEmployee.FirstName         = model.FirstName;
            dbEmployee.LastName          = model.LastName;
            dbEmployee.Salary            = model.Salary;
            dbEmployee.StartDate         = model.StartDate;
            dbEmployee.VacationDays      = model.VacationDays;

            await this.DbContext.SaveChangesAsync();

            return(dbEmployee);
        }