private object GetMonitorAlertClientModel(MVDMonitorAlert monitorAlert) { return(new { monitorAlert.Title, monitorAlert.ChannelType, ChannelTypeText = monitorAlert.ChannelType.ToString(), monitorAlert.Settings }); }
public async Task <IActionResult> Post([FromBody] MVMMonitorAlertSave value) { if (string.IsNullOrWhiteSpace(value.Title)) { return(Error("Title is required.")); } if (value.MonitorId == Guid.Empty) { return(Error("Monitor Id is required.")); } var monitor = await Db.Monitors.FirstOrDefaultAsync(x => x.MonitorId == value.MonitorId && x.UserId == UserId); if (monitor == null) { return(Error("Monitor not found.")); } MVDMonitorAlert data = null; if (value.Id != Guid.Empty) { data = await Db.MonitorAlerts.FirstOrDefaultAsync(x => x.MonitorId == monitor.MonitorId && x.MonitorAlertId == value.Id); if (data == null) { return(Error("Monitor alert not found.")); } } else { if (!await CheckSubscription(UserId, "ALERT_CHANNEL")) { return(Error("You don't have enough quota to do that.")); } data = new MVDMonitorAlert { MonitorAlertId = Guid.NewGuid(), MonitorId = monitor.MonitorId, Title = value.Title, ChannelType = value.ChannelType, Settings = JsonConvert.SerializeObject(value.Settings) }; await Db.AddAsync(data); } var result = await Db.SaveChangesAsync(); if (result > 0) { return(Success("Monitor alert saved successfully.", new { Id = data.MonitorAlertId })); } else { return(Error("Something is wrong with your model.")); } }