private void PrepareViewBag(ActivityLogCreateViewModel model) { IEnumerable <SelectListItem> types = from ActivityLogTypes a in Enum.GetValues(typeof(ActivityLogTypes)) select new SelectListItem { Value = ((int)a).ToString(), Text = a.GetDisplayName() }; ViewBag.TypesSelect = new MultiSelectList(types, "Value", "Text", model.Types); }
public async Task <int> InsertActivity(ActivityLogCreateViewModel createModel, int userId) { ActivityLogModel model = (ActivityLogModel)createModel; model.CreatedBy = userId; int activityId = await ActivityLogRepository.InsertActivity(model, userId); await ActivityLogRepository.MergeActivityTypes(activityId, createModel.Types); return(activityId); }
public async Task InsertActivityBlock(HttpSessionStateBase session, ActivityLogCreateViewModel model) { using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) { int activityId = await InsertActivity(model, (session["User"] as UserModel).Id); await AssociatePeopleWithActivity(session, activityId, model.SessionId); ClearSession(session, model.SessionId); scope.Complete(); } }
/// <summary> /// /// </summary> /// <param name="viewModel"></param> /// <returns></returns> public async Task CreateByViewModelAsync(ActivityLogCreateViewModel viewModel) { // Check if (viewModel == null) { throw new ArgumentException(nameof(viewModel)); } // Process var activityLog = _mapper.Map <ActivityLog>(viewModel); _activityLogs.Add(activityLog); await _unitOfWork.SaveAllChangesAsync(auditUserId : _httpContextManager.CurrentUserId()); }
public async Task <ActionResult> Add(ActivityLogCreateViewModel model) { if (ModelState.IsValid) { try { await ActivityService.InsertActivityBlock(Session, model); return(RedirectToAction("List")); } catch (Exception e) { MvcApplication.LogException(e); ModelState.AddModelError("Title", "There was an error saving. It has been logged for later review."); } } PrepareViewBag(model); return(View(model)); }