public async Task InsertStudent(StudentPromoModel model, int?userId, Guid promoToken, string remoteIp) { using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) { int studentId = await StudentRepository.InsertStudent(model); model.Id = studentId; await StudentPromoRepository.Save(model.Id, promoToken); if (userId.HasValue) { await EventLogService.AddStudentEvent(userId.Value, model.Id, EventLogTypes.EditStudent, remoteIp); } else { await EventLogService.AddStudentEvent(model.Id, EventLogTypes.EditStudent, remoteIp); } scope.Complete(); } }
public async Task <ActionResult> Form(StudentPromoModel model) { HttpCookie cookie = HttpContext.Request.Cookies["promo"]; if (ModelState.IsValid) { int?userId = null; if (Session["User"] != null) { userId = (Session["User"] as UserModel).Id; } await StudentService.InsertStudent(model, userId, Guid.Parse(cookie.Value), HttpContext.Request.UserHostAddress); return(RedirectToAction("Success")); } await PrepareDropDowns(); return(View(model)); }