public virtual async Task <ActionResult> Add(AddCompetitorViewModel competitorModel) { var canAddCompetitor = await _participationService.CanAddCompetitor(competitorModel.ParticipationId, Convert.ToInt32(User.Identity.Name)); if (!canAddCompetitor) { ModelState.AddModelError("", "شما امکان ثبت بازیکن جدید را ندارید."); return(this.JsonValidationErrors()); } var tmpPath = Server.MapPath("~/App_Data/tmp/"); var userImagePath = Server.MapPath("~/App_Data/User_Image/"); var studentCertificateImagePath = Server.MapPath("~/App_Data/Student_Certificate_Image/"); var insuranceImagePath = Server.MapPath("~/App_Data/Insurance_Image/"); var azmoonImagePath = Server.MapPath("~/App_Data/Azmoon_Confirmation_Image/"); var fullName = string.Format("{0}-{1}", competitorModel.FirstName, competitorModel.LastName).ApplyCorrectYeKe(); await CopyFileAsync(tmpPath + competitorModel.UserImage, userImagePath + string.Format("{0}-{1}", fullName, competitorModel.UserImage)); competitorModel.UserImage = string.Format("{0}-{1}", fullName, competitorModel.UserImage); await CopyFileAsync(tmpPath + competitorModel.StudentCertificateImage, studentCertificateImagePath + string.Format("{0}-{1}", fullName, competitorModel.StudentCertificateImage)); competitorModel.StudentCertificateImage = string.Format("{0}-{1}", fullName, competitorModel.StudentCertificateImage); await CopyFileAsync(tmpPath + competitorModel.InsuranceImage, insuranceImagePath + string.Format("{0}-{1}", fullName, competitorModel.InsuranceImage)); competitorModel.InsuranceImage = string.Format("{0}-{1}", fullName, competitorModel.InsuranceImage); await CopyFileAsync(tmpPath + competitorModel.AzmoonConfirmationImage, azmoonImagePath + string.Format("{0}-{1}", fullName, competitorModel.AzmoonConfirmationImage)); competitorModel.AzmoonConfirmationImage = string.Format("{0}-{1}", fullName, competitorModel.AzmoonConfirmationImage); var competitor = new DomainClasses.Competitor() { FirstName = competitorModel.FirstName, LastName = competitorModel.LastName, FatherName = competitorModel.FatherName, BirthDate = competitorModel.BirthDate, ParticipateId = competitorModel.ParticipationId, PhoneNumber = competitorModel.PhoneNumber, StudentCertificateImage = competitorModel.StudentCertificateImage, StudentNumber = competitorModel.StudentNumber, StudyFieldId = competitorModel.StudyFieldId, StudyFieldDegreeId = competitorModel.StudyFieldDegreeId, UserImage = competitorModel.UserImage, Weight = competitorModel.Weight, Height = competitorModel.Height, NationalCode = competitorModel.NationalCode, MobileNumber = competitorModel.MobileNumber, Email = competitorModel.Email, InsuranceNumber = competitorModel.InsuranceNumber, InsuranceImage = competitorModel.InsuranceImage, InsuranceEndDate = competitorModel.InsuranceEndDate, AzmoonConfirmationImage = competitorModel.AzmoonConfirmationImage }; _competitorService.Add(competitor); await _dbContext.SaveChangesAsync(); return(Json(new { competitor.Id, competitor.UserImage })); }
public virtual async Task<ActionResult> Add(AddCompetitorViewModel competitorModel) { var canAddCompetitor = await _participationService.CanAddCompetitor(competitorModel.ParticipationId, Convert.ToInt32(User.Identity.Name)); if (!canAddCompetitor) { ModelState.AddModelError("", "شما امکان ثبت بازیکن جدید را ندارید."); return this.JsonValidationErrors(); } var tmpPath = Server.MapPath("~/App_Data/tmp/"); var userImagePath = Server.MapPath("~/App_Data/User_Image/"); var studentCertificateImagePath = Server.MapPath("~/App_Data/Student_Certificate_Image/"); var insuranceImagePath = Server.MapPath("~/App_Data/Insurance_Image/"); var azmoonImagePath = Server.MapPath("~/App_Data/Azmoon_Confirmation_Image/"); var fullName = string.Format("{0}-{1}", competitorModel.FirstName, competitorModel.LastName).ApplyCorrectYeKe(); await CopyFileAsync(tmpPath + competitorModel.UserImage, userImagePath + string.Format("{0}-{1}", fullName, competitorModel.UserImage)); competitorModel.UserImage = string.Format("{0}-{1}", fullName, competitorModel.UserImage); await CopyFileAsync(tmpPath + competitorModel.StudentCertificateImage, studentCertificateImagePath + string.Format("{0}-{1}", fullName, competitorModel.StudentCertificateImage)); competitorModel.StudentCertificateImage = string.Format("{0}-{1}", fullName, competitorModel.StudentCertificateImage); await CopyFileAsync(tmpPath + competitorModel.InsuranceImage, insuranceImagePath + string.Format("{0}-{1}", fullName, competitorModel.InsuranceImage)); competitorModel.InsuranceImage = string.Format("{0}-{1}", fullName, competitorModel.InsuranceImage); await CopyFileAsync(tmpPath + competitorModel.AzmoonConfirmationImage, azmoonImagePath + string.Format("{0}-{1}", fullName, competitorModel.AzmoonConfirmationImage)); competitorModel.AzmoonConfirmationImage = string.Format("{0}-{1}", fullName, competitorModel.AzmoonConfirmationImage); var competitor = new DomainClasses.Competitor() { FirstName = competitorModel.FirstName, LastName = competitorModel.LastName, FatherName = competitorModel.FatherName, BirthDate = competitorModel.BirthDate, ParticipateId = competitorModel.ParticipationId, PhoneNumber = competitorModel.PhoneNumber, StudentCertificateImage = competitorModel.StudentCertificateImage, StudentNumber = competitorModel.StudentNumber, StudyFieldId = competitorModel.StudyFieldId, StudyFieldDegreeId = competitorModel.StudyFieldDegreeId, UserImage = competitorModel.UserImage, Weight = competitorModel.Weight, Height = competitorModel.Height, NationalCode = competitorModel.NationalCode, MobileNumber = competitorModel.MobileNumber, Email = competitorModel.Email, InsuranceNumber = competitorModel.InsuranceNumber, InsuranceImage = competitorModel.InsuranceImage, InsuranceEndDate = competitorModel.InsuranceEndDate, AzmoonConfirmationImage = competitorModel.AzmoonConfirmationImage }; _competitorService.Add(competitor); await _dbContext.SaveChangesAsync(); return Json(new { competitor.Id, competitor.UserImage }); }