public async Task <IActionResult> Edit(int id, [Bind("Id,Customer_Id,Type,Condition,Value")] Notification_Rule notification_Rule) { if (id != notification_Rule.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(notification_Rule); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!Notification_RuleExists(notification_Rule.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(notification_Rule)); }
public async Task <IActionResult> Create([Bind("Id,Customer_Id,Type,Condition,Value")] Notification_Rule notification_Rule) { if (ModelState.IsValid) { _context.Add(notification_Rule); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(notification_Rule)); }
public async Task NotificationRule_Create_Invalid_Notification_Test() { //Arrange var user = new ClaimsPrincipal(new ClaimsIdentity(new Claim[] { new Claim(ClaimTypes.Name, "example name"), new Claim(ClaimTypes.NameIdentifier, "1"), new Claim("custom-claim", "example claim value"), }, "mock")); var optionsBuilder = new DbContextOptionsBuilder <ApplicationDbContext>(); optionsBuilder.UseInMemoryDatabase(databaseName: "CommerceTestDB"); var _dbContext = new ApplicationDbContext(optionsBuilder.Options); var controller = new NotificationController(_dbContext); controller.ControllerContext = new ControllerContext() { HttpContext = new DefaultHttpContext() { User = user } }; var notificationRule = new Notification_Rule(); notificationRule.Type = "Deposit"; notificationRule.Condition = "NA"; notificationRule.Value = -1; //Act var result = await controller.Create(notificationRule); //Assert Assert.NotNull(result); }
public async Task <IActionResult> Create(Notification_Rule notification_Rule) { notification_Rule.Customer_Id = User.FindFirstValue(ClaimTypes.NameIdentifier); if ((ModelState.IsValid) && (notification_Rule.Type == "Login" || notification_Rule.Type == "Balance" || notification_Rule.Type == "Deposit" || notification_Rule.Type == "Withdrawal") && (notification_Rule.Condition == "Above" || notification_Rule.Condition == "Below" || notification_Rule.Condition == "NA") && (notification_Rule.Value >= 0)) { if ((notification_Rule.Type == "Deposit" || notification_Rule.Type == "Withdrawal") && (notification_Rule.Value <= 0)) { return(View(notification_Rule)); } if (notification_Rule.Type == "Login") { notification_Rule.Condition = "NA"; notification_Rule.Value = 0; } if (notification_Rule.Message == null || notification_Rule.Message.ToString() == "") { notification_Rule.Message = "NA"; } var param = new SqlParameter[] { new SqlParameter() { ParameterName = "@customer_id", SqlDbType = System.Data.SqlDbType.NVarChar, Size = 450, Direction = System.Data.ParameterDirection.Input, Value = User.FindFirstValue(ClaimTypes.NameIdentifier) }, new SqlParameter() { ParameterName = "@type", SqlDbType = System.Data.SqlDbType.VarChar, Size = 32, Direction = System.Data.ParameterDirection.Input, Value = notification_Rule.Type }, new SqlParameter() { ParameterName = "@condition", SqlDbType = System.Data.SqlDbType.VarChar, Size = 32, Direction = System.Data.ParameterDirection.Input, Value = notification_Rule.Condition }, new SqlParameter() { ParameterName = "@value", SqlDbType = System.Data.SqlDbType.Decimal, /*Precision = 18, * Scale = 2,*/ Direction = System.Data.ParameterDirection.Input, Value = notification_Rule.Value }, new SqlParameter() { ParameterName = "@notify_text", SqlDbType = System.Data.SqlDbType.Bit, Direction = System.Data.ParameterDirection.Input, Value = notification_Rule.Notify_Text }, new SqlParameter() { ParameterName = "@notify_email", SqlDbType = System.Data.SqlDbType.Bit, Direction = System.Data.ParameterDirection.Input, Value = notification_Rule.Notify_Email }, new SqlParameter() { ParameterName = "@notify_web", SqlDbType = System.Data.SqlDbType.Bit, Direction = System.Data.ParameterDirection.Input, Value = notification_Rule.Notify_Web }, new SqlParameter() { ParameterName = "@message", SqlDbType = System.Data.SqlDbType.VarChar, Size = 300, Direction = System.Data.ParameterDirection.Input, Value = notification_Rule.Message } }; await _context.Database.ExecuteSqlRawAsync("[dbo].[AddNotificationRule] @customer_id, @type, @condition, @value, @notify_text, @notify_email, @notify_web, @message", param); await _context.SaveChangesAsync(); return(RedirectToAction("Manage")); } return(View(notification_Rule)); }
public async Task <IActionResult> EditConfirmed(Notification_Rule notification_Rule, int id) { var param = new SqlParameter[] { new SqlParameter() { ParameterName = "@id", SqlDbType = System.Data.SqlDbType.Int, Direction = System.Data.ParameterDirection.Input, Value = id }, new SqlParameter() { ParameterName = "@customer_id", SqlDbType = System.Data.SqlDbType.NVarChar, Size = 450, Direction = System.Data.ParameterDirection.Input, Value = User.FindFirstValue(ClaimTypes.NameIdentifier) }, new SqlParameter() { ParameterName = "@type", SqlDbType = System.Data.SqlDbType.VarChar, Size = 32, Direction = System.Data.ParameterDirection.Input, Value = notification_Rule.Type }, new SqlParameter() { ParameterName = "@condition", SqlDbType = System.Data.SqlDbType.VarChar, Size = 32, Direction = System.Data.ParameterDirection.Input, Value = notification_Rule.Condition }, new SqlParameter() { ParameterName = "@value", SqlDbType = System.Data.SqlDbType.Decimal, /*Precision = 18, * Scale = 2,*/ Direction = System.Data.ParameterDirection.Input, Value = notification_Rule.Value }, new SqlParameter() { ParameterName = "@notify_text", SqlDbType = System.Data.SqlDbType.Bit, Direction = System.Data.ParameterDirection.Input, Value = notification_Rule.Notify_Text }, new SqlParameter() { ParameterName = "@notify_email", SqlDbType = System.Data.SqlDbType.Bit, Direction = System.Data.ParameterDirection.Input, Value = notification_Rule.Notify_Email }, new SqlParameter() { ParameterName = "@notify_web", SqlDbType = System.Data.SqlDbType.Bit, Direction = System.Data.ParameterDirection.Input, Value = notification_Rule.Notify_Web }, new SqlParameter() { ParameterName = "@message", SqlDbType = System.Data.SqlDbType.VarChar, Size = 300, Direction = System.Data.ParameterDirection.Input, Value = notification_Rule.Message } }; await _context.Database.ExecuteSqlRawAsync("[dbo].[EditNotificationRule] @id, @customer_id, @type, @condition, @value, @notify_text, @notify_email, @notify_web, @message", param); await _context.SaveChangesAsync(); return(RedirectToAction("Manage")); }