Ejemplo n.º 1
0
        public IActionResult Edit(int Id)
        {
            var employee = _EmployeeService.GetById(Id);

            if (employee == null)
            {
                return(NotFound());
            }
            var model = new EmployeeEditViewmodel()
            {
                Id            = employee.Id,
                EmpNo         = employee.EmpNo,
                FirstName     = employee.FirstName,
                MiddleName    = employee.MiddleName,
                LastName      = employee.LastName,
                Gender        = employee.Gender,
                Address       = employee.Address,
                City          = employee.City,
                PostalCode    = employee.PostalCode,
                PhoneNumber   = employee.PhoneNumber,
                DOB           = employee.DOB,
                DateJoined    = employee.DateJoined,
                Designation   = employee.Designation,
                Email         = employee.Email,
                InsuranceNo   = employee.InsuranceNo,
                PaymentMethod = employee.PaymentMethod,
                StudentLoan   = employee.StudentLoan,
                UnionMember   = employee.UnionMember,
            };

            return(View(model));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Edit(EmployeeEditViewmodel model)
        {
            if (ModelState.IsValid)
            {
                var employee = _EmployeeService.GetById(model.Id);
                if (employee == null)
                {
                    return(NotFound());
                }
                employee.EmpNo         = model.EmpNo;
                employee.FirstName     = model.FirstName;
                employee.MiddleName    = model.MiddleName;
                employee.LastName      = model.LastName;
                employee.InsuranceNo   = model.InsuranceNo;
                employee.PhoneNumber   = model.PhoneNumber;
                employee.Email         = model.Email;
                employee.Gender        = model.Gender;
                employee.DOB           = model.DOB;
                employee.Designation   = model.Designation;
                employee.DateJoined    = model.DateJoined;
                employee.City          = model.City;
                employee.Address       = model.Address;
                employee.PostalCode    = model.PostalCode;
                employee.PaymentMethod = model.PaymentMethod;
                employee.StudentLoan   = model.StudentLoan;
                employee.UnionMember   = model.UnionMember;
                if (model.ImageUrl != null && model.ImageUrl.Length > 0)
                {
                    var UploadDir = @"Images/employeeDP";
                    var Filename  = Path.GetFileNameWithoutExtension(model.ImageUrl.FileName);
                    var Extension = Path.GetExtension(model.ImageUrl.FileName);
                    var WebRoot   = _hostingEnvironment.WebRootPath;
                    Filename = DateTime.UtcNow.ToString("yyyymmdd") + Filename + Extension;
                    var path = Path.Combine(WebRoot, UploadDir, Filename);
                    await model.ImageUrl.CopyToAsync(new FileStream(path, FileMode.Create));

                    employee.ImageUrl = "/" + UploadDir + "/" + Filename;
                }
                await _EmployeeService.UpdateAsync(employee);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(model));
        }