public List <ClientNotifications> Notifications(string numCarte) { SqlConnection Conn; SqlCommand command; SqlDataAdapter adapter = new SqlDataAdapter(); DataSet ds = new DataSet(); Conn = new SqlConnection(Startup.DSN_EXTRANET); Conn.Open(); List <ClientNotifications> list_notif_client = new List <ClientNotifications>(); command = new SqlCommand("Notifications_Fidelite", Conn); command.CommandType = CommandType.StoredProcedure; command.CommandTimeout = 750; command.Parameters.Add("@NUMERO_CARTE", SqlDbType.VarChar).Value = numCarte; adapter.SelectCommand = command; adapter.Fill(ds); adapter.Dispose(); command.Dispose(); for (int i = 0; i <= ds.Tables[0].Rows.Count - 1; i++) { ClientNotifications notif_client = new ClientNotifications(); notif_client.CLI_PROMO_COURRIER = Convert.ToInt32(ds.Tables[0].Rows[i]["CLI_PROMO_COURRIER"].ToString()); notif_client.CLI_PROMO_EMAIL = Convert.ToInt32(ds.Tables[0].Rows[i]["CLI_PROMO_EMAIL"].ToString()); notif_client.CLI_PROMO_SMS = Convert.ToInt32(ds.Tables[0].Rows[i]["CLI_PROMO_SMS"].ToString()); list_notif_client.Add(notif_client); } Conn.Dispose(); return(list_notif_client); }
public void ClientNotification_Serialization() { //Arrange var controller = new NullController(); controller.InjectDependencies(new FakeBackOfficeRequestContext(new FakeRebelApplicationContext(false))); var notifications = new ClientNotifications(controller.ControllerContext); var msg1 = new NotificationMessage("hello", "world"); var msg2 = new NotificationMessage("world", NotificationType.Error); var msg3 = new NotificationMessage("good", NotificationType.Warning); var msg4 = new NotificationMessage("bye", NotificationType.Success); //Act notifications.Add(msg1); notifications.Add(msg2); notifications.Add(msg3); notifications.Add(msg4); //Assert var serializeed = notifications.ToJsonString(); Assert.AreEqual(@"[{""id"":""" + msg1.Id.ToString("N") + @""",""message"":""hello"",""title"":""world"",""type"":""info""},{""id"":""" + msg2.Id.ToString("N") + @""",""message"":""world"",""title"":"""",""type"":""error""},{""id"":""" + msg3.Id.ToString("N") + @""",""message"":""good"",""title"":"""",""type"":""warning""},{""id"":""" + msg4.Id.ToString("N") + @""",""message"":""bye"",""title"":"""",""type"":""success""}]", serializeed); }
public async Task <IActionResult> CompanyRegistration(CompanyRegistartionViewModel model) { if (ModelState.IsValid) { var user = _mapper.MapCompanyRegistartionViewModelToApplicationUser(model); var result = await _userManager.CreateAsync(user, model.Password); if (result.Succeeded) { if (!_roleManager.Roles.Any(x => x.Name == "Client")) { var role = new IdentityRole { Name = ERole.Client.ToString() }; await _roleManager.CreateAsync(role); } await _userManager.AddToRoleAsync(user, ERole.Client.ToString()); var noti = new ClientNotifications { CreatedDate = DateTime.Now, ToClientId = user.Id, FromRole = ERole.Admin, IsRead = false, NotiBody = "Hello " + user.CompanyName + " in our system!", NotiHeader = "Welcome ;)" }; try { _context.ClientNotifications.Add(noti); _context.SaveChanges(); } catch (Exception ex) { _logger.LogError("Error within saveing notification after registration", ex); } return(RedirectToAction("Success", "Success")); } else { _logger.LogWarning("Can't create Company user, something wrong with User Identity"); return(RedirectToAction("Error", "Error")); } } else { _logger.LogWarning("While creating user occur invalid model"); return(View(model)); } }
public async Task <IActionResult> Summary(SummaryViewModel summary, bool isOkay) { if (ModelState.IsValid && isOkay) { var model = _mapper.MapSummaryViewModelToFormModel(summary); model.CreatedDate = DateTime.Now; model.ApplicationUser = await _userManager.FindByIdAsync(summary.UserId); var empTask = _mapper.MapSummaryViewModelToEmployeeTask(summary); empTask.isDone = false; var clientNoti = new ClientNotifications { CreatedDate = DateTime.Now, FromRole = ERole.Admin, ToClientId = summary.UserId, IsRead = false, NotiBody = "Hello your form is sent.", NotiHeader = "Form confirmation" }; var adminNoti = new AdminNotifications { CreatedDate = DateTime.Now, FromUserId = summary.UserId, ToRole = ERole.Admin, IsRead = false, NotiBody = "Client with id " + summary.UserId + "sent form. ", NotiHeader = "New form from Client " + summary.Company }; try { _notificationRepository.AddNotificationsForClient(clientNoti); _notificationRepository.AddNotificationsForAdmin(adminNoti); _employeeTaskRepository.AddEmployeeTask(empTask); _formRepository.AddTask(model); } catch (Exception e) { _logger.LogError("Error while adding to database", e); Console.WriteLine(e.Message); // add alert in view } return(RedirectToAction("Success", "Success")); } else { _logger.LogWarning("Invalid modelstate in summary"); } return(View(summary)); }
public void ClientNotification_Unique_Messages_Only() { //Arrange var controller = new NullController(); controller.InjectDependencies(new FakeBackOfficeRequestContext(new FakeRebelApplicationContext(false))); var notifications = new ClientNotifications(controller.ControllerContext); var msg = new NotificationMessage("hello"); //Act notifications.Add(msg); notifications.Add(msg); }
public void ClientNotification_Message_Added() { //Arrange var controller = new NullController(); controller.InjectDependencies(new FakeBackOfficeRequestContext(new FakeRebelApplicationContext(false))); var notifications = new ClientNotifications(controller.ControllerContext); var msg = new NotificationMessage("hello"); //Act notifications.Add(msg); //Assert Assert.AreEqual(1, notifications.Count()); }
public bool Notifications(string numCarte, ClientNotifications clientNotifications) { SqlTransaction Trans = null; bool TransOuverte = false; try { SqlConnection Conn; SqlCommand command; Conn = new SqlConnection(Startup.DSN_EXTRANET); Conn.Open(); TransOuverte = true; Trans = Conn.BeginTransaction(); command = new SqlCommand("Notifications_Fidelite_update", Conn, Trans); command.CommandType = CommandType.StoredProcedure; command.CommandTimeout = 750; command.Parameters.Add("@NUMERO_CARTE", SqlDbType.VarChar).Value = numCarte; command.Parameters.Add("@COURRIER", SqlDbType.Int).Value = clientNotifications.CLI_PROMO_COURRIER; command.Parameters.Add("@EMAIL", SqlDbType.Int).Value = clientNotifications.CLI_PROMO_EMAIL; command.Parameters.Add("@SMS", SqlDbType.Int).Value = clientNotifications.CLI_PROMO_SMS; command.ExecuteNonQuery(); command.Dispose(); Trans.Commit(); Trans.Dispose(); Conn.Dispose(); return(true); } catch (Exception e) { if (TransOuverte) { Trans.Rollback(); Trans.Dispose(); } Console.WriteLine(e); return(false); } }
protected BackOfficeController(IBackOfficeRequestContext requestContext) { BackOfficeRequestContext = requestContext; Notifications = new ClientNotifications(ControllerContext); ActionInvoker = new RebelBackOfficeActionInvoker(requestContext); }
public void AddNotificationsForClient(ClientNotifications notifi) { _context.ClientNotifications.Add(notifi); _context.SaveChanges(); }
public NotificationViewModel MapClientNotificationsToNotificationViewModel(ClientNotifications clientNotifications) { return(_mapper.Map <NotificationViewModel>(clientNotifications)); }