public int UpdateAlertRule(AlertRuleDetail objRule, int UserId) { int result = 0; try { Alert_Rules objalertRule = objDbMrpEntities.Alert_Rules.Where(a => a.RuleId == objRule.RuleId && a.UserId == UserId).FirstOrDefault(); if (objalertRule != null) { objalertRule.EntityId = Int32.Parse(objRule.EntityID); objalertRule.EntityType = objRule.EntityType; objalertRule.Indicator = objRule.Indicator; objalertRule.IndicatorComparision = objRule.IndicatorComparision;; objalertRule.IndicatorGoal = Int32.Parse(objRule.IndicatorGoal); objalertRule.CompletionGoal = Int32.Parse(objRule.CompletionGoal); objalertRule.Frequency = objRule.Frequency; if (objRule.Frequency == Convert.ToString(SyncFrequencys.Weekly)) { objalertRule.DayOfWeek = Convert.ToByte(objRule.DayOfWeek); } if (objRule.Frequency == Convert.ToString(SyncFrequencys.Monthly)) { if (objRule.DateOfMonth != null) { objalertRule.DateOfMonth = Convert.ToByte(objRule.DateOfMonth); } else { objalertRule.DateOfMonth = 10; } } objalertRule.ModifiedDate = DateTime.Now; objalertRule.ModifiedBy = UserId; objalertRule.RuleSummary = objRule.RuleSummary; objalertRule.LastProcessingDate = DateTime.Now; objalertRule.IsDisabled = false; objDbMrpEntities.Entry(objalertRule).State = EntityState.Modified; result = objDbMrpEntities.SaveChanges(); } } catch (Exception ex) { Elmah.ErrorSignal.FromCurrentContext().Raise(ex); } return(result); }
public int DisableAlertRule(int RuleId, bool RuleOn) { int result = 0; bool Isdisable = RuleOn == true ? false : true; try { Alert_Rules objrule = objDbMrpEntities.Alert_Rules.Where(a => a.RuleId == RuleId).FirstOrDefault(); objrule.IsDisabled = Isdisable; objDbMrpEntities.Entry(objrule).State = EntityState.Modified; result = objDbMrpEntities.SaveChanges(); } catch (Exception ex) { Elmah.ErrorSignal.FromCurrentContext().Raise(ex); } return(result); }
public int DeleteAlertRule(int RuleId) { int result = 0; try { //delete alert related to rule var lstAlerts = objDbMrpEntities.Alerts.Where(a => a.RuleId == RuleId).ToList(); lstAlerts.ForEach(alert => objDbMrpEntities.Entry(alert).State = EntityState.Deleted); objDbMrpEntities.SaveChanges(); //delete rule Alert_Rules objrule = objDbMrpEntities.Alert_Rules.Where(a => a.RuleId == RuleId).FirstOrDefault(); objDbMrpEntities.Entry(objrule).State = EntityState.Deleted; result = objDbMrpEntities.SaveChanges(); } catch (Exception ex) { Elmah.ErrorSignal.FromCurrentContext().Raise(ex); } return(result); }