private EventConfigurationViewModel GetModel() { int userId = UserHelper.GetUserByIdentityName(User.Identity.Name).Id; var configs = EventConfigurationHelper.GetUserEventConfigurations(userId); var model = new EventConfigurationViewModel() { Configurations = new List <EventConfigRow>(), Properties = DataConfigurationHelper.GetUserDataProperties(userId), CurrentConfig = GetEmptyCurrentConfig(userId), Response = string.Empty }; foreach (var config in configs) { model.Configurations.Add(new EventConfigRow { Id = config.Id, Rule = EventConfigurationHelper.FormatEventToString(config), Period = config.Period }); } return(model); }
public async Task <ActionResult> Add(EventConfigurationViewModel data) { var response = string.Empty; try { if (ModelState.IsValid) { int userId = UserHelper.GetUserByIdentityName(User.Identity.Name).Id; var config = GetEventConfigurationFromForm(userId, data.CurrentConfig); if (IsNewConfiguration(data.CurrentConfig.Id)) { EventConfigurationHelper.AddConfiguration(config); response = "Event Configuration added successfully"; } else { EventConfigurationHelper.UpdateConfiguration(config); response = "Event Configuration updated successfully"; } } } catch (Exception ex) { _logger.Error(ex.Message); } var model = GetModel(); model.Response = response; return(View("Index", model)); }