public async Task <ActionResult> Edit(TechnicalStaffViewModel technicalStaffModel) { var selectedTechnicalStaff = await _technicalStaffService.Find(technicalStaffModel.Id); var userId = Convert.ToInt32(User.Identity.Name); if (selectedTechnicalStaff.IsApproved == null || selectedTechnicalStaff.IsApproved == true) { var canEdit = await _competitionService.CanEditCommonTechnicalStaff(technicalStaffModel.CompetitionId, userId); if (!canEdit) { ModelState.AddModelError("", "امکان ویرایش کادر اجرایی وجود ندارد."); return(this.JsonValidationErrors()); } } else { var canEdit = await _competitionService.CanEditRejectedCommonTechnicalStaff(technicalStaffModel.CompetitionId, userId); if (!canEdit) { ModelState.AddModelError("", "امکان ویرایش کادر اجرایی وجود ندارد."); return(this.JsonValidationErrors()); } } if (technicalStaffModel.Image != selectedTechnicalStaff.Image) { var tmpPath = Server.MapPath("~/App_Data/tmp/"); var fullName = string.Format("{0}-{1}", technicalStaffModel.FirstName, technicalStaffModel.LastName).ApplyCorrectYeKe(); var userImagePath = Server.MapPath("~/App_Data/TechnicalStaff_Image/"); await CopyFileAsync(tmpPath + technicalStaffModel.Image, userImagePath + string.Format("{0}-{1}", fullName, technicalStaffModel.Image)); try { System.IO.File.Delete(userImagePath + selectedTechnicalStaff.Image); } catch (Exception) { } selectedTechnicalStaff.Image = string.Format("{0}-{1}", fullName, technicalStaffModel.Image); } selectedTechnicalStaff.FirstName = technicalStaffModel.FirstName; selectedTechnicalStaff.LastName = technicalStaffModel.LastName; selectedTechnicalStaff.FatherName = technicalStaffModel.FatherName; selectedTechnicalStaff.NationalCode = technicalStaffModel.NationalCode; selectedTechnicalStaff.BirthDate = technicalStaffModel.BirthDate; selectedTechnicalStaff.MobileNumber = technicalStaffModel.MobileNumber; selectedTechnicalStaff.IsApproved = null; var selectedCompetitionTechnicalStaff = await _commonTechnicalStaffService.GetCompetitionTechnicalStaff(technicalStaffModel.Id, Convert.ToInt32(User.Identity.Name)); if (technicalStaffModel.TechnicalStaffRoleId != selectedCompetitionTechnicalStaff.TechnicalStaffRoleId) { selectedCompetitionTechnicalStaff.TechnicalStaffRoleId = technicalStaffModel.TechnicalStaffRoleId; } await _dbContext.SaveChangesAsync(); return(new HttpStatusCodeResult(HttpStatusCode.OK)); }