public virtual ActionResult ApplyStage(int id) { var stage = _stageRepository.GetById(id); if (stage != null) { var applyViewModel = new ViewModels.Student.Apply(); applyViewModel.IdStage = id; applyViewModel.IdStudent = _httpContextService.GetUserId(); return(View(applyViewModel)); } return(HttpNotFound()); }
public virtual ActionResult ApplyStage(IEnumerable <HttpPostedFileBase> files, ViewModels.Student.Apply applyStudentViewModel) { var stage = _stageRepository.GetById(applyStudentViewModel.IdStage); var studentID = _httpContextService.GetUserId(); if (stage == null) { ViewBag.Message = StudentResources.NoFileToUpload; return(HttpNotFound()); } var appliedStages = _applyRepository.GetAll().Where(x => x.IdStudent == studentID); if (appliedStages != null) { foreach (var appliedStage in appliedStages) { if (stage.Id == appliedStage.IdStage) { this.Flash(FlashMessageResources.AlreadyApplied, FlashEnum.Info); return(View(applyStudentViewModel)); } } } if (files.Any(file => file == null || (!file.FileName.Contains(".pdf") && !file.FileName.Contains(".do")))) { this.Flash(FlashMessageResources.InvalidFile, FlashEnum.Error); return(View(applyStudentViewModel)); } var readFile = new ReadFile(); if (readFile.ReadFileCVLetter(files, Server, applyStudentViewModel.IdStage, applyStudentViewModel.IdStudent)) { var files1 = files.ToList(); applyStudentViewModel.Cv = applyStudentViewModel.IdStage + "-" + applyStudentViewModel.IdStudent + "-CV-" + files1[0].FileName; applyStudentViewModel.Letter = applyStudentViewModel.IdStage + "-" + applyStudentViewModel.IdStudent + "-LP-" + files1[1].FileName; var newApplicationStudent = Mapper.Map <Stagio.Domain.Entities.Apply>(applyStudentViewModel); newApplicationStudent.Status = 0; //0 = En attente newApplicationStudent.DateApply = DateTime.Now; _applyRepository.Add(newApplicationStudent); _stageRepository.Update(stage); TempData["files"] = files; var student = _studentRepository.GetById(applyStudentViewModel.IdStudent); string messageToCoordinator = String.Format(StudentToCoordinator.ApplyMessage, student.FirstName, student.LastName, stage.Id, stage.StageTitle); _notificationService.SendNotificationToAllCoordinator(StudentToCoordinator.ApplyTilte, messageToCoordinator); string messageToContactEnterprise = String.Format(StudentToContactEnterprise.ApplyMessage, student.FirstName, student.LastName, stage.Id, stage.StageTitle); _notificationService.SendNotificationToAllContactEnterpriseOf(stage.CompanyName, StudentToContactEnterprise.ApplyTitle, messageToContactEnterprise); this.Flash(FlashMessageResources.AddSuccess, FlashEnum.Success); return(RedirectToAction(MVC.Student.ApplyConfirmation())); } else { this.Flash(FlashMessageResources.ErrorsOnPage, FlashEnum.Error); return(View(applyStudentViewModel)); } }