Example #1
0
 public Alert(AlertDto dto)
 {
     Id          = dto.Id;
     Message     = dto.Message;
     DateCreated = dto.DateCreated;
     CreatedBy   = dto.CreatedBy;
 }
Example #2
0
        public void AppendAlert(AlertDto alert)
        {
            string alertStatus = "";

            switch (alert.AlertStatus)
            {
            case AlertStatus.StockAlert:
                alertStatus = "Alarm";
                this._alertBuilder.AppendLine("<tr style=\"background-color: #ff5050\">");
                break;

            case AlertStatus.StockWarning:
                alertStatus = "Warning";
                this._alertBuilder.AppendLine("<tr style=\"background-color: #ccff33\">");
                break;

            case AlertStatus.StockNoAlert:
                alertStatus = "Okay";
                this._alertBuilder.AppendLine("<tr style=\"background-color: #00ff99\">");
                break;

            default:
                alertStatus = "";
                this._alertBuilder.AppendLine("<tr>");
                break;
            }
            //this._alertBuilder.AppendLine("<tr>");
            this._alertBuilder.AppendFormat("<td>{0}</td>", alert.AlertIdentifier).AppendLine();
            this._alertBuilder.AppendFormat("<td>{0}</td>", alert.AlertType).AppendLine();
            this._alertBuilder.AppendFormat("<td>{0}</td>", alertStatus).AppendLine();
            this._alertBuilder.AppendFormat("<td>{0}</td>", alert.Quantity).AppendLine();
            this._alertBuilder.AppendFormat("<td>{0}</td>", alert.MinQuantity).AppendLine();
            this._alertBuilder.AppendFormat("<td>{0}</td>", alert.SafeQuantity).AppendLine();
            this._alertBuilder.AppendLine("</tr>");
        }
        private void Save(object sender)
        {
            AlertDto alert;

            if (Alert != null)
            {
                alert = Alert;
            }
            else
            {
                alert = new AlertDto
                {
                    Id      = 0,
                    HouseId = SelectedHouse.Id,
                    Type    = new AlertTypeDto()
                    {
                        Id = SelectedType.Id
                    },
                    ServiceType = new AlertServiceTypeDto()
                    {
                        Id = SelectedService.Id
                    },
                };
            }
            alert.StartDate   = FromDate;
            alert.EndDate     = ToDate;
            alert.Description = Description;

            _requestService.SaveAlert(alert);
            _view.DialogResult = true;
        }
        public IHttpActionResult getAlerts()
        {
            List <AlertDto> a      = new List <AlertDto>();
            var             alerts = DataContext.Alerts.Include("Contacts").ToList();


            //foreach(var a in alerts)
            //{
            //    var updates = DataContext.UpdateAlerts.Where(x => x.OriginAlertRefId == a.AlertId);
            //    foreach (var u in updates)
            //        a.Updates.Add(u);
            //}
            foreach (var s in alerts)
            {
                if (s.Status != AlertStatus.Complete)  //want to return only active alerts
                {
                    var aDto = new AlertDto()
                    {
                        AlertId      = s.AlertId,
                        Description  = s.Description,
                        Status       = s.Status.ToString().ToUpper(),
                        Start_Time   = s.Status != AlertStatus.Pending ? String.Format("{0:MM/dd/yyyy hh:mm tt}", s.Start_Time) : "STILL PENDING",
                        Title        = s.Title,
                        location_lat = s.location_lat,
                        location_lng = s.location_lng,
                        Radius       = s.Radius
                    };

                    a.Add(aDto);
                }
            }
            return(Ok(a));
        }
        public IHttpActionResult getAlertById(int id)                       //this is for the update page. Finds the correct alert to display
        {
            List <UpdateAlertDto> updateList = new List <UpdateAlertDto>(); //for update DTOS for formatting stuff for table
            List <object>         request    = new List <object>();
            var alert = DataContext.Alerts.Find(id);

            alert.Contacts = DataContext.Contacts.Include("Address").Where(x => x.Alerts.Any(y => y.AlertId == id)).ToList();
            var    updates = DataContext.UpdateAlerts.Where(x => x.OriginAlertRefId == alert.AlertId);
            string path;

            if (string.IsNullOrEmpty(alert.ImageName))            //TODO: uncomment when done
            {
                path = "Shrek.jpeg";
            }
            else
            {
                path = alert.ImageName;
            }

            if (updates != null)
            {
                foreach (var u in updates)
                {
                    u.OriginAlert = null;
                    alert.Updates.Add(u);

                    var updateDto = new UpdateAlertDto()
                    {
                        UpdateId    = u.UpdateId,
                        Title       = u.Title,
                        Description = u.Description,
                        Update_Time = String.Format("{0:MM/dd/yyyy hh:mm tt}", u.Start_Time),
                        Status      = u.Status == null ? "UPDATED" : u.Status.ToUpper()
                    };

                    updateList.Add(updateDto);
                }
            }
            var aDto = new AlertDto()
            {
                AlertId      = alert.AlertId,
                Description  = alert.Description,
                Status       = alert.Status.ToString().ToUpper(),
                Start_Time   = String.Format("{0:MM/dd/yyyy hh:mm tt}", alert.Start_Time),
                Title        = alert.Title,
                location_lat = alert.location_lat,
                location_lng = alert.location_lng,
                Radius       = alert.Radius,
                ImagePath    = path,
                Contacts     = alert.Contacts.ToList()
            };

            request.Add(alert);
            request.Add(aDto);
            if (updateList.Count > 0)
            {
                request.Add(updateList);
            }
            return(Ok(request));
        }
        public IHttpActionResult GetAlerts()
        {
            // Get the rows from the Alerts table and put them in a List object.
            List <Alert> myalert = db.alerts.ToList();

            // Create a List object to hold the dtos.
            List <AlertDto> AlertDtos = new List <AlertDto> {
            };

            // Convert each Alert into a AlertDto and put it in the list.
            foreach (var Alert in myalert)
            {
                AlertDto NewAlert = new AlertDto
                {
                    // Set the dto properties.
                    alertId     = Alert.alertId,
                    title       = Alert.title,
                    dateTime    = Alert.dateTime,
                    description = Alert.description,
                };

                // Add the dto to the list.
                AlertDtos.Add(NewAlert);
            }

            // Return the Ok http action result containing the dto list.
            return(Ok(AlertDtos));
        }
        public AlertAndWorkDialogViewModel(AlertDto alert)
        {
            Alert           = alert;
            _requestService = new RequestService(AppSettings.DbConnection);

            StreetList  = new ObservableCollection <StreetDto>();
            HouseList   = new ObservableCollection <HouseDto>();
            CityList    = new ObservableCollection <CityDto>(_requestService.GetCities());
            TypeList    = new ObservableCollection <AlertTypeDto>(_requestService.GetAlertTypes());
            ServiceList = new ObservableCollection <AlertServiceTypeDto>(_requestService.GetAlertServiceTypes());
            FromDate    = _requestService.GetCurrentDate().Date;

            SelectedType    = TypeList.FirstOrDefault();
            SelectedService = ServiceList.FirstOrDefault();
            SelectedCity    = CityList.FirstOrDefault();
            if (Alert != null)
            {
                SelectedStreet  = StreetList.FirstOrDefault(s => s.Id == Alert.StreetId);
                SelectedHouse   = HouseList.FirstOrDefault(s => s.Id == Alert.HouseId);
                SelectedType    = TypeList.FirstOrDefault(t => t.Id == Alert.Type.Id);
                SelectedService = ServiceList.FirstOrDefault(s => s.Id == Alert.ServiceType.Id);
                Description     = Alert.Description;
                FromDate        = Alert.StartDate;
                ToDate          = Alert.EndDate;
            }
        }
Example #8
0
 public static Alert ToEntity(this AlertDto dto)
 {
     return(new Alert
     {
         Id = dto.Id,
         DateHour = dto.DateHour
     });
 }
        public async Task CreateAlert(int alertType, string description)
        {
            var dto = new AlertDto
            {
                Type        = alertType,
                Description = description
            };
            var transportationId = _configurationService.GetCurrentTransportationId();

            if (transportationId != null)
            {
                await _apiService.PostAlert(transportationId.Value, dto);
            }
        }
        public ActionResult DeleteConfirm(int id)
        {
            string url = "AlertData/GetAlert/" + id;
            HttpResponseMessage response = client.GetAsync(url).Result;

            if (response.IsSuccessStatusCode)
            {
                AlertDto SelectedAlert = response.Content.ReadAsAsync <AlertDto>().Result;
                return(View(SelectedAlert));
            }
            else
            {
                return(RedirectToAction("Error"));
            }
        }
        // GET: api/AlertData/5
        public IHttpActionResult GetAlert(int id)
        {
            //When I run my view, It is telling me myalert is null. Unsure why.
            Alert    myalert  = db.alerts.Find(id);
            AlertDto alertDto = new AlertDto
            {
                alertId      = myalert.alertId,
                title        = myalert.title,
                dateTime     = myalert.dateTime,
                description  = myalert.description,
                EventId      = myalert.eventId == null ? 0 : (int)myalert.eventId,
                jobPostingId = myalert.jobPostingId == null ? 0 : (int)myalert.jobPostingId
            };

            return(Ok(alertDto));
        }
Example #12
0
        public async Task PostAlert(Guid transportationId, AlertDto dto)
        {
            var client  = new RestClient(_configurationService.WebApiUrl);
            var request = new RestRequest(_configurationService.PostAlertApiEndpoint, Method.POST);

            request.AddUrlSegment("transportationId", transportationId);
            request.AddHeader("Authorization", await _authenticationService.GetAuthorizationHeaderAsync());
            request.AddJsonBody(dto);

            var response = await client.ExecuteTaskAsync(request);

            if (!response.IsSuccessful)
            {
                throw response.ErrorException;
            }
        }
        // GET: Alert/Edit/5
        public ActionResult Edit(int id)
        {
            // Create the string just as you would if you were typing it in the browser.
            string url = "AlertData/GetAlert/" + id;

            // Send the http request and get an http action response.
            HttpResponseMessage response = client.GetAsync(url).Result;

            // The http call worked.
            if (response.IsSuccessStatusCode)
            {
                AlertDto SelectedAlert = response.Content.ReadAsAsync <AlertDto>().Result;
                return(View(SelectedAlert));
            }

            return(RedirectToAction("Error"));
        }
Example #14
0
        public IHttpActionResult SetConfirmation(PublishDto dto)
        {
            try
            {
                AlertDto alert = new AlertDto();


                var result = Confirmation.Pending;
                switch (dto.Confirmation)
                {
                case 0:
                    result           = Confirmation.Pass;
                    alert.AlertClass = "success";
                    alert.AlertText  = "Δημοσιευμένη";
                    break;

                case 1:
                    result           = Confirmation.Pending;
                    alert.AlertClass = "warning";
                    alert.AlertText  = "Εκκρεμών";
                    break;

                case 2:
                    result           = Confirmation.Cancel;
                    alert.AlertClass = "danger";
                    alert.AlertText  = "Απορριφθείσα";
                    break;
                }

                var confirm = _ctx.Houses
                              .Find(dto.Id);

                confirm.IsConfirmed = result;
                _ctx.SaveChanges();

                return(Ok(alert));
            }

            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
        public AlertDto GetAlert(string userCode)
        {
            var alertsDto = new List <AlertDto>();
            var alerts    = _repository.GetAllByFilter <Alert>(x => x.UserCode == userCode);

            if (alerts.Count == 0)
            {
                return(null);
            }
            foreach (var alert in alerts)
            {
                var alertDto = new AlertDto
                {
                    Title = alert.Title,
                    Body  = alert.Body
                };
                alertsDto.Add(alertDto);
                _repository.Delete(alert);
                _repository.Save();
            }


            return(alertsDto[0]);
        }
        // GET: Alert/Details/5
        public ActionResult Details(int id)
        {
            // Create the string just as you would if you were typing it in the browser.
            string url = "AlertData/GetAlert/" + id;

            // Send the http request and get an http action response.
            HttpResponseMessage response = client.GetAsync(url).Result;

            // The http call worked.
            if (response.IsSuccessStatusCode)
            {
                ViewAlert ViewAlert = new ViewAlert();
                AlertDto  alertDto  = response.Content.ReadAsAsync <AlertDto>().Result;
                ViewAlert.alert = alertDto;

                if (alertDto.EventId != 0)
                {
                    EventDto eventDto = GetEventDto(alertDto.EventId);
                    ViewAlert.eventDto = eventDto;
                }
                return(View(ViewAlert));
            }
            return(RedirectToAction("Error"));
        }
        public async Task <ActionResult> PostAlert([FromRoute] Guid transportationId, [FromBody] AlertDto alertDto)
        {
            var sessionId   = Guid.NewGuid().ToString();
            var postMessage = new PostAlertMessage
            {
                AlertDto         = alertDto,
                TransportationId = transportationId
            };
            var message = new BrokeredMessage(postMessage)
            {
                SessionId = sessionId
            };
            const string queueName           = "Incoming-Post-Alert-Queue";
            const string processsedQueueName = "Processed-Post-Alert-Queue";
            await _messageBrokerService.SendBrokeredMessage(message, queueName);

            await _messageBrokerService.WaitOnBrokeredMessage <PostAlertResultMessage>(processsedQueueName, sessionId,
                                                                                       5);

            return(NoContent());
        }
Example #18
0
        public ActionResult EditAd(int Id)
        {
            try
            {
                var house = _ctx.Houses
                            .Include(x => x.HousePhotos)
                            .Include("State")
                            .Include("State.Areas")
                            .Single(x => x.Id == Id);

                var states = _ctx.States.ToList();

                AlertDto alert = new AlertDto();
                switch (house.IsConfirmed)
                {
                case (Confirmation)0:
                    alert.AlertClass = "success";
                    alert.AlertText  = "Δημοσιευμένη";
                    break;

                case (Confirmation)1:
                    alert.AlertClass = "warning";
                    alert.AlertText  = "Εκκρεμών";
                    break;

                case (Confirmation)2:
                    alert.AlertClass = "danger";
                    alert.AlertText  = "Απορριφθείσα";
                    break;
                }

                AdFormViewModel vm = new AdFormViewModel
                {
                    States = states,
                    Areas  = house.State.Areas,
                    Id     = house.Id,
                    Alert  = alert,
                    House  = new House
                    {
                        AreaId        = house.State.Areas.FirstOrDefault(x => x.Id == house.AreaId).Id,
                        StateId       = house.State.Id,
                        Address       = house.Address,
                        IsConfirmed   = house.IsConfirmed,
                        PostalCode    = house.PostalCode,
                        Gender        = house.Gender,
                        Smoker        = house.Smoker,
                        RentCost      = house.RentCost,
                        Level         = house.Level,
                        SquareMeters  = house.SquareMeters,
                        Pets          = house.Pets,
                        HousePhotos   = house.HousePhotos,
                        TotalRooms    = house.TotalRooms,
                        YearConstruct = house.YearConstruct,
                        Description   = house.Description
                    }
                };


                return(View(vm));
            }
            catch (Exception ex)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, $"{ex.Message}"));
            }
        }
 public AlertUseCaseInput(int userId, AlertDto alertDto, AlertAction alertAction)
 {
     this.UserId      = userId;
     this.AlertDto    = alertDto;
     this.AlertAction = alertAction;
 }