public string Update(Staff user, string CurrentUsername)
        {
            Staff  FoundedStaff = FindById(user.Id, CurrentUsername);
            string Password     = user.Login.Password;

            if (FoundedStaff != null)
            {
                if (DepartmentService.FindById(user.Department.Id, CurrentUsername) != null)
                {
                    if (IsValisImage(user))
                    {
                        UpdateImageFile(user);
                        user.StaffId        = FoundedStaff.StaffId;
                        user.Login.IsActive = Status.Enable;
                        user.Login          = FoundedStaff.Login;
                        user.Login.Password = Password;
                        return(StaffRepository.Update(user) ? null : Messages.IssueInDatabase);
                    }
                    else
                    {
                        return(Messages.InvalidImage);
                    }
                }
                else
                {
                    return(Messages.ProgramNotFound);
                }
            }
            else
            {
                return(Messages.IdExist);
            }
        }
        public ActionResult Save(Staff staffentity)
        {
            bool status  = false;
            var  message = "";

            //Validation
            try
            {
                if (staffentity != null)
                {
                    var staffobj = _staffRepository.GetByID(staffentity.ID);

                    if (staffobj != null)
                    {
                        staffobj.Name     = staffentity.Name;
                        staffobj.Location = staffentity.Location;
                        _staffRepository.Update(staffobj);
                        status = true;
                    }
                    else
                    {
                        _staffRepository.Add(staffentity);
                        status = true;
                    }
                }
            }
            catch (Exception e)
            {
                status  = false;
                message = e.Message;
            }
            return(new JsonResult {
                Data = new { status = status, msg = message }
            });
        }
        //public async Task<IActionResult> AddAsync(EditCustomerViewModel model, string returnUrl = null)
        public async Task <IActionResult> Edit(StaffViewModel model, string returnUrl = null)
        {
            ViewData["ReturnUrl"] = returnUrl;
            if (ModelState.IsValid)
            {
                var user = await _userManager.FindByIdAsync(model.Id);

                // Update it with the values from the view model
                user.FirstName   = model.FirstName;
                user.LastName    = model.LastName;
                user.UserName    = model.UserName;
                user.Email       = model.Email;
                user.PhoneNumber = model.PhoneNumber;
                user.Address     = model.Address; //custom property
                user.Description = model.Description;
                if (!string.IsNullOrWhiteSpace(model.Password))
                {
                    user.PasswordHash = _userManager.PasswordHasher.HashPassword(user, model.Password);
                }
                try
                {
                    var result = await _userManager.UpdateAsync(user);

                    if (result.Succeeded)
                    {
                        var staff      = _staffRepository.Get(user.Id);
                        var staffParam = new DynamicParameters();
                        staffParam.Add(nameof(Staff.Id), user.Id);
                        staffParam.Add(nameof(Staff.StaffCode), staff.StaffCode); //Don't allow your user to edit
                        staffParam.Add(nameof(Staff.Title), model.Title);
                        staffParam.Add(nameof(Staff.Salary), model.Salary);
                        //var createdAt = new DateTimeOffset(DateTime.UtcNow).ToUnixTimeMilliseconds();


                        var unixHireDate = ConvertStringToUnixTimestamp(model.HireDateStr);
                        staffParam.Add(nameof(Staff.HireDate), unixHireDate);

                        _staffRepository.Update(user.Id, staffParam);
                        _staffRepository.Commit();
                        _logger.LogInformation("Staff updated.");
                        //return RedirectToLocal(returnUrl);
                        return(RedirectToAction(nameof(StaffsController.Index), "Staffs"));
                    }
                    AddErrors(result);
                }
                catch (Exception ex)
                {
                    _staffRepository.RollBack();
                    _logger.LogError(default(EventId), ex, "Error updating staff");
                    throw;
                }
            }


            return(View(model));
        }
 public void UpdatePerson(Person person)
 {
     db.Update(person);
 }
Beispiel #5
0
 public bool Update(Staff staff)
 {
     return(staffRepository.Update(staff));
 }
Beispiel #6
0
 public bool UpdateBooking(int staff_id, Staff s)
 {
     return(repo.Update(s));
 }