public void TriggerAlerts(INotifications notifications, SettingsModel settings, AlertModel alert)
        {
            if (settings.Sound.IsEnabled)
            {
                PlaySound(settings.Sound.FilePath);
            }

            AlertModel alertCopy = alert.Clone() as AlertModel;

            alertCopy.Price = Math.Round(alertCopy.Price, settings.Alerts.MaxPriceDecimalPlacesNumber);

            if (!alertCopy.Time.Offset.Equals(settings.Alerts.TimeZone.BaseUtcOffset))
            {
                alertCopy.Time = alert.Time.ToOffset(settings.Alerts.TimeZone.BaseUtcOffset);
            }

            if (settings.Email.IsEnabled)
            {
                SendEmail(notifications, settings.Email, alertCopy);
            }

            if (settings.Telegram.IsEnabled)
            {
                SendTelegramMessage(settings.Telegram, alertCopy);
            }
        }
        private void AddAlert(AlertModel alert)
        {
            AlertModel alertCopy = alert.Clone() as AlertModel;

            if (!alertCopy.Time.Offset.Equals(_settings.Alerts.TimeZone.BaseUtcOffset))
            {
                alertCopy.Time = alert.Time.ToOffset(_settings.Alerts.TimeZone.BaseUtcOffset);
            }

            alertCopy.Price = Math.Round(alertCopy.Price, Settings.Alerts.MaxPriceDecimalPlacesNumber);

            if (!Alerts.Contains(alertCopy))
            {
                Alerts.Add(alertCopy);

                VisibleAlert = alertCopy;
            }
        }
Exemple #3
0
        /// <summary>
        /// Offer from Project to Vessel
        /// Validations
        /// Insert offer with Status NEW
        /// Send alert to Vessel company owners
        /// Send mail to Vessel company owners
        /// </summary>
        /// <param name="offer"></param>
        /// <returns></returns>
        public RequestResult <List <AlertModel> > InsComplete(OfferModel offer)
        {
            RequestResult <List <AlertModel> > resp = new RequestResult <List <AlertModel> >()
            {
                Status = Status.Success
            };
            OfferDA           offerDA        = new OfferDA();
            VesselServices    vesselServices = new VesselServices();
            PersonServices    personServices = new PersonServices();
            AlertServices     alertServices  = new AlertServices();
            List <AlertModel> lstAlertToSend = new List <AlertModel>();
            MailServices      MailServ       = new MailServices();
            ITemplate         factory        = new TemplateMessagesFactory();

            TransactionOptions scopeOptions = new TransactionOptions();

            ////scopeOptions.IsolationLevel = IsolationLevel.ReadCommitted;
            using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required, scopeOptions))
            {
                try
                {
                    if (offer.Vessel.VesselId == null)
                    {
                        throw new Exception("VesselId REQUIRED");
                    }
                    if (offer.Project.ProjectId == null)
                    {
                        throw new Exception("ProjectId REQUIRED");
                    }
                    if (offer.ProjectAdmin.PersonId == null)
                    {
                        throw new Exception("ProjectAdmin.PersonId REQUIRED");
                    }

                    OfferModel        val    = new OfferModel();
                    List <OfferModel> lstVal = new List <OfferModel>();
                    val.Project.ProjectId = offer.Project.ProjectId;
                    val.Vessel.VesselId   = offer.Vessel.VesselId;
                    lstVal = Get(val);

                    if (lstVal.Count > 0)
                    {
                        throw new Exception("STATUS_NOT_VALID");
                    }

                    VesselModel vessel = new VesselModel();
                    vessel.VesselId = offer.Vessel.VesselId;
                    vessel          = vesselServices.Get(vessel).FirstOrDefault();

                    // Insert offer with Status NEW
                    var respOffer = offerDA.InsUpd(offer);
                    if (respOffer.Status != Status.Success)
                    {
                        throw new Exception(respOffer.Message);
                    }

                    // Send alert to Vessel company owners
                    //Listado de los usuarios de una compañía
                    UserPersonModel person = new UserPersonModel();
                    person.CompanyId = vessel.Company.CompanyId;
                    List <UserPersonModel> lst = personServices.getUserPerson(person);

                    Dictionary <string, string> values = new Dictionary <string, string>();
                    values.Add("IMO", vessel.Imo);
                    values.Add("VESSELNAME", vessel.Name);
                    AlertModel alert = alertServices.GetWithValues(6, values);

                    SystemVariableServices        SVS   = new SystemVariableServices();
                    Dictionary <string, string[]> param = new Dictionary <string, string[]>();
                    string EgulfUrl = SVS.GetSystemVariableValue("EgulfWeb");
                    param.Add("{Enfasis}", new string[] { vessel.Imo, vessel.Name });
                    param.Add("{Btn_url}", new string[] { EgulfUrl });
                    foreach (UserPersonModel personItem in lst)
                    {
                        AlertModel alertAux = alert.Clone();
                        alertAux.To = personItem.PersonId;
                        lstAlertToSend.Add(alertAux);
                        MailServ.SendMail(factory.GetTemplate(personItem.Email, "VesselOfferReceived", param));
                    }

                    var respAlert = alertServices.InsUpd(lstAlertToSend);
                    if (respAlert != null)
                    {
                        throw new Exception(respAlert.Message);
                    }

                    resp.Data = lstAlertToSend;

                    ts.Complete();
                }
                catch (Exception ex)
                {
                    ts.Dispose();
                    resp = new RequestResult <List <AlertModel> >()
                    {
                        Status = Status.Error, Message = ex.Message
                    };
                    Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
                    throw ex;
                }
            }
            return(resp);
        }