Esempio n. 1
0
        public async Task<ActionResult> Index(string[] SelectedCities, Notification notification)
        {
            if (Session["User"] == null)
            {
                return RedirectToAction("LogOff", "Account");
            }

            User user = Session["User"] as User;

            if (SelectedCities == null)
            {
                TempData["Message"] = "Seleccione al menos una ciudad.";
                var response = await cities.GetCities();
                ViewBag.CitiesList = response.Data;
                return View(notification);
            }

            try
            {
                List<Notification> notifications = new List<Notification>();
                foreach (string city in SelectedCities)
                {
                    notifications.Add(new Notification()
                    {
                        ID_CITY = city,
                        ID_DEPENDENCY =user.ID_DEPENDENCY,
                        NOTIFICATION_TEXT = notification.NOTIFICATION_TEXT,
                        CREATED_DATE = DateTime.Now
                    });
                }

                NotificationRepository notificationRespository = new NotificationRepository();
                RepositoryResponse<List<Notification>> response = await notificationRespository.AddNotifications(notifications);

                if (response.Success)
                {
                    TempData["Message"] = MvcHtmlString.Create("Notificación enviada exitosamente.");
                }
                else
                {
                    TempData["Message"] = "Se produjo un error, por favor intente nuevamente.";
                }
            }
            catch(Exception ex){
                TempData["Message"] = "Se produjo un error, por favor intente nuevamente.";
                Trace.TraceError(ex.Message);
            }

            return RedirectToAction("Index");
        }
        public void AddNotifications_Success()
        {
            NotificationRepository repository = new NotificationRepository();

            Notification notification = new Notification {
                NOTIFICATION_TEXT="Unit Test notification",
                ID_DEPENDENCY = "iIAW2gamws",
                ID_CITY = "vxwnP2GrHn"
            };

            RepositoryResponse<Notification> expected = new RepositoryResponse<Notification> { Success = true,
                Data= notification
            };

            RepositoryResponse<Notification> result = repository.AddNotification(notification).GetAwaiter().GetResult();

            Assert.IsTrue(result.Success, "Notifications not created");
            Assert.IsNotNull(result.Data);
            Assert.IsNull(result.Error,"Some error ocurred");
        }