public async Task <ActionResult> Edit(EditStudyAbroadViewModel model) { if (ModelState.IsValid) { await StudyAbroadService.Update(model, (Session["User"] as UserModel).Id, HttpContext.Request.UserHostAddress); return(RedirectToAction("View", "Student", new { Id = model.StudentId })); } try { ViewBag.Student = await StudentService.GetStudent(model.StudentId); } catch (Exception e) { string message = string.Format("Invalid student ID {0}", model.StudentId); MvcApplication.LogException(new ArgumentException(message, nameof(model), e)); return(RedirectToAction("NotFound", "Error")); } await PrepareDropDowns(); return(View(model)); }
public async Task <ActionResult> Edit(int id) { StudyAbroadViewModel study = await StudyAbroadService.FindById(id); if (study == null) { string message = string.Format("Study abroad experience ID {0} not found", id); MvcApplication.LogException(new ArgumentException(message, nameof(id))); return(RedirectToAction("NotFound", "Error")); } try { ViewBag.Student = await StudentService.GetStudent(study.StudentId); } catch (Exception e) { string message = string.Format("Invalid student ID {0}", study.StudentId); MvcApplication.LogException(new ArgumentException(message, nameof(id), e)); return(RedirectToAction("NotFound", "Error")); } EditStudyAbroadViewModel model = (EditStudyAbroadViewModel)study; await PrepareDropDowns(); return(View(model)); }
public async Task Update(EditStudyAbroadViewModel model, int userId, string remoteIp) { try { using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) { await StudyAbroadRepository.Update(model); await EventLogService.AddStudentEvent(userId, model.StudentId, EventLogTypes.EditStudentExperience, remoteIp); scope.Complete(); } } catch (Exception) { } }
public async Task Update(EditStudyAbroadViewModel model) { const string sql = @" UPDATE [dbo].[StudyAbroad] SET [StudentId] = @StudentId, [Semester] = @Semester, [Year] = @Year, [StartDate] = @StartDate, [EndDate] = @EndDate, [CreditBearing] = @CreditBearing, [Internship] = @Internship, [CountryId] = @CountryId, [City] = @City, [ProgramId] = @ProgramId WHERE Id = @Id"; try { if (model.StartDate.HasValue) { model.StartDate = model.StartDate.Value.ToUniversalTime(); } if (model.EndDate.HasValue) { model.EndDate = model.EndDate.Value.ToUniversalTime(); } await UnitOfWork.Context().ExecuteAsync(sql, model); } catch (Exception e) { e.Data["SQL"] = sql; ErrorStore.LogException(e, HttpContext.Current); throw e; } await ReplaceProgramTypes(model.Id, model.ProgramTypes); }