Exemplo n.º 1
0
        public async Task <ActionResult> Add(AddStudyAbroadViewModel model)
        {
            if (ModelState.IsValid)
            {
                await StudyAbroadService.Save(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));
        }
Exemplo n.º 2
0
        public async Task Save(AddStudyAbroadViewModel model)
        {
            const string sql = @"
                INSERT INTO [dbo].[StudyAbroad]
                (
                    StudentId, Year, Semester, CreditBearing, Internship,
                    CountryId, ProgramId, StartDate, EndDate, City
                )
                OUTPUT INSERTED.Id
                VALUES
                (
                    @StudentId, @Year, @Semester, @CreditBearing, @Internship,
                    @CountryId, @ProgramId, @StartDate, @EndDate, @City
                )";

            if (model.StartDate.HasValue)
            {
                model.StartDate = model.StartDate.Value.ToUniversalTime();
            }

            if (model.EndDate.HasValue)
            {
                model.EndDate = model.EndDate.Value.ToUniversalTime();
            }

            int studyAbroadId;

            try
            {
                studyAbroadId = (await UnitOfWork.Context().QueryAsync <int>(sql,
                                                                             new
                {
                    StudentId = model.StudentId,
                    Year = model.Year,
                    Semester = model.Semester,
                    CreditBearing = model.CreditBearing,
                    Internship = model.Internship,
                    CountryId = model.CountryId,
                    ProgramId = model.ProgramId,
                    StartDate = model.StartDate,
                    EndDate = model.EndDate,
                    City = model.City
                })).Single();
            }
            catch (Exception e)
            {
                e.Data["SQL"] = sql;
                ErrorStore.LogException(e, HttpContext.Current);
                throw e;
            }

            try
            {
                await ReplaceProgramTypes(studyAbroadId, model.ProgramTypes);
            }
            catch (Exception)
            {
                // Caught and logged already.
            }
        }
Exemplo n.º 3
0
        public async Task Save(AddStudyAbroadViewModel model, int userId, string remoteIp)
        {
            using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                await StudyAbroadRepository.Save(model);

                await EventLogService.AddStudentEvent(userId, model.StudentId, EventLogTypes.AddStudentExperience,
                                                      remoteIp);
            }
        }