public void SaveAlertrule() { MRPEntities db = new MRPEntities(); HttpContext.Current = DataHelper.SetUserAndPermission(); UserController objUserController = new UserController(); objUserController.ControllerContext = new ControllerContext(MockHelpers.FakeUrlHelper.FakeHttpContext(), new RouteData(), objUserController); objUserController.Url = MockHelpers.FakeUrlHelper.UrlHelper(); AlertRuleDetail objRule = new AlertRuleDetail(); objRule.RuleId = 0; objRule.EntityID = Convert.ToString(DataHelper.GetPlanId()); objRule.RuleSummary = "<h4> Responses are less than 75% of Goal</h4><br/><span>Start at 50% completion</span><span>Repeat Daily</span>"; objRule.EntityType = "Plan"; objRule.Indicator = "MQL"; objRule.IndicatorComparision = "LT"; objRule.IndicatorGoal = "25"; objRule.CompletionGoal = "25"; objRule.Frequency = "Daily"; var result = objUserController.SaveAlertRule(objRule, 0) as JsonResult; Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().Name + " \n The Assert Value result : " + result.Data); Assert.IsNotNull(result.Data); }
public void DeleteAlertrule() { MRPEntities db = new MRPEntities(); HttpContext.Current = DataHelper.SetUserAndPermission(); UserController objUserController = new UserController(); objUserController.ControllerContext = new ControllerContext(MockHelpers.FakeUrlHelper.FakeHttpContext(), new RouteData(), objUserController); objUserController.Url = MockHelpers.FakeUrlHelper.UrlHelper(); AlertRuleDetail objRule = new AlertRuleDetail(); int ruleId = 0; int entityid = (DataHelper.GetPlanId()); objRule.RuleId = 0; objRule.EntityID = Convert.ToString(entityid); objRule.RuleSummary = "test alert rule"; objRule.EntityType = "Plan"; objRule.Indicator = "MQL"; objRule.IndicatorComparision = "LT"; objRule.IndicatorGoal = "25"; objRule.CompletionGoal = "25"; objRule.Frequency = "Daily"; var result = objUserController.SaveAlertRule(objRule, 0) as JsonResult; var rules = db.Alert_Rules.Where(a => a.RuleSummary == "test alert rule" && a.EntityId == entityid).Select(a => a).FirstOrDefault(); if (rules != null) { ruleId = rules.RuleId; } result = objUserController.DeleteAlertRule(ruleId) as JsonResult; Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().Name + " \n The Assert Value result : " + result.Data); Assert.IsNotNull(result.Data); }
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 AddUpdate_AlertRule(AlertRuleDetail objRule, int ClientId, int UserId, int RuleId) { int result = 0; int IsExists = 0; var Connection = objDbMrpEntities.Database.Connection as SqlConnection; if (Connection.State == System.Data.ConnectionState.Closed) { Connection.Open(); } byte?DayOfWeek = null, DateOfMonth = null; using (SqlCommand command = new SqlCommand("SP_Save_AlertRule", Connection)) { try { command.CommandType = CommandType.StoredProcedure; if (objRule.Frequency == Convert.ToString(SyncFrequencys.Weekly)) { DayOfWeek = Convert.ToByte(objRule.DayOfWeek); } if (objRule.Frequency == Convert.ToString(SyncFrequencys.Monthly)) { if (objRule.DateOfMonth != null) { DateOfMonth = Convert.ToByte(objRule.DateOfMonth); } else { DateOfMonth = 10; } } command.Parameters.AddWithValue("@ClientId", ClientId); command.Parameters.AddWithValue("@RuleId", RuleId); command.Parameters.AddWithValue("@RuleSummary", objRule.RuleSummary); command.Parameters.AddWithValue("@EntityId", Int32.Parse(objRule.EntityID)); command.Parameters.AddWithValue("@EntityType", objRule.EntityType); command.Parameters.AddWithValue("@Indicator", objRule.Indicator); command.Parameters.AddWithValue("@IndicatorComparision", objRule.IndicatorComparision); command.Parameters.AddWithValue("@IndicatorGoal", Int32.Parse(objRule.IndicatorGoal)); command.Parameters.AddWithValue("@CompletionGoal", Int32.Parse(objRule.CompletionGoal)); command.Parameters.AddWithValue("@Frequency", objRule.Frequency); command.Parameters.AddWithValue("@DayOfWeek", DayOfWeek); command.Parameters.AddWithValue("@DateOfMonth", DateOfMonth); command.Parameters.AddWithValue("@UserId", UserId); command.Parameters.AddWithValue("@CreatedBy", UserId); command.Parameters.AddWithValue("@ModifiedBy", UserId); command.Parameters.AddWithValue("@UserEmail", Sessions.User.Email.ToString());//*Added User Email Column for ticket - 2534*/ command.Parameters.AddWithValue("@IsExists", IsExists).Direction = ParameterDirection.Output; SqlDataAdapter adp = new SqlDataAdapter(command); command.CommandTimeout = 0; command.ExecuteNonQuery(); result = Convert.ToInt32(command.Parameters["@IsExists"].Value); } catch (Exception ex) { Elmah.ErrorSignal.FromCurrentContext().Raise(ex); return(-1); } finally { if (Connection.State == System.Data.ConnectionState.Open) { Connection.Close(); } } } return(result); }