Exemplo n.º 1
0
        static void Main(string[] args)
        {
            using (var dataContext = new DataContext())
            {
                var t = dataContext.EvidenceLogs
                        .Include(f => f.InfringementEvidences)
                        .ToList();

                //dataContext.Database.Log = (s) => System.Diagnostics.Debug.WriteLine(s);
                Company company = dataContext.Companies.Find(1);
                User    user    = dataContext.Users.Find(2);

                //var targetMobileNumber = "095 080 5791";
                //var targetMobileNumber = "096 213 8481";
                var targetMobileNumber = "0845766144";
                var isValid            = Msisdn.IsValid(targetMobileNumber, Country);

                var msisdn = new Msisdn(targetMobileNumber, Country);

                Router router = new Router()
                {
                    Source = "IMS", Target = msisdn.ToString(Msisdn.Format.International)
                };
                SmsPayload payload = new SmsPayload("FirtNotice", "CM", "Traffic Offence. Download at http://www.ims.africa/Notification/Verify?refNo=123456789");
                Item.Initiate(dataContext, "internal reference", company, user, router, payload, false);
            }

            System.Console.ReadKey();
        }
        internal ShippingDetails Map()
        {
            var email  = new EmailAddress(Email);
            var msisdn = new Msisdn(Msisdn);

            return(new ShippingDetails(email, msisdn, ShippingAddress));
        }
Exemplo n.º 3
0
        public BillingDetails Map()
        {
            var email  = new EmailAddress(Email);
            var msisdn = new Msisdn(Msisdn);

            return(new BillingDetails(email, msisdn, BillingAddress));
        }
Exemplo n.º 4
0
        public override bool Equals(Object obj)
        {
            if (this == obj)
            {
                return(true);
            }
            if (obj == null)
            {
                return(false);
            }
            if (GetType() != obj.GetType())
            {
                return(false);
            }
            Conversation other = (Conversation)obj;

            if (Msisdn == null)
            {
                if (other.Msisdn != null)
                {
                    return(false);
                }
            }
            else if (Msisdn.CompareTo(other.Msisdn) != 0)
            {
                return(false);
            }
            if (OnHike != other.OnHike)
            {
                return(false);
            }
            return(true);
        }
Exemplo n.º 5
0
        public override int  GetHashCode()
        {
            const int prime  = 31;
            int       result = 1;

            result = prime * result + ((Msisdn == null) ? 0 : Msisdn.GetHashCode());
            result = prime * result + (OnHike ? 1231 : 1237);
            return(result);
        }
Exemplo n.º 6
0
        public IHttpActionResult SendNoticeSms(IList <string> referenceNumbers)
        {
            using (var dataContext = new DataContext())
            {
                var response = new List <SendResponseModel>();
                var company  = dataContext.Companies.FirstOrDefault(f => f.Name == "Intelligent Mobility Solutions");
                var corresponedenceTemplate = dataContext.CorrespondenceTemplates
                                              .AsNoTracking()
                                              .FirstOrDefault(f => f.Key == "FirstNotice" && f.CorrespondenceType == Core.Data.Enums.CorrespondenceType.Sms);

                foreach (var referenceNumber in referenceNumbers)
                {
                    var register = dataContext.Registers
                                   .Include(f => f.Person)
                                   .FirstOrDefault(f => f.ReferenceNumber == referenceNumber);

                    var person = register.Person;
                    if (person == null)
                    {
                        response.Add(new SendResponseModel {
                            ReferenceNumber = referenceNumber, IsError = true, Error = "No person associated with the offence."
                        });
                        continue;
                    }

                    var isValid = Msisdn.IsValid(person.MobileNumber, Country);
                    if (!isValid)
                    {
                        // TODO: feedback that Msisdn is invalid and cannot be trusted
                        response.Add(new SendResponseModel {
                            ReferenceNumber = referenceNumber, IsError = true, Error = "Invalid Msisdn."
                        });
                        continue;
                    }

                    var message = corresponedenceTemplate.Generate(new Dictionary <string, string> {
                        { "referenceNumber", referenceNumber }
                    });
                    Router router = new Router()
                    {
                        Source = "IMS", Target = new Msisdn(person.MobileNumber, Country).ToString(Msisdn.Format.International)
                    };
                    SmsPayload payload = new SmsPayload("FirstNoticeSms", "CM", message);
                    Item.Initiate(dataContext, referenceNumber, company, person, router, payload, false);

                    dataContext.SaveChanges();

                    response.Add(new SendResponseModel {
                        ReferenceNumber = referenceNumber, IsError = false
                    });
                }

                return(Ok(response));
            }
        }
Exemplo n.º 7
0
        public override int GetHashCode()
        {
            const int prime  = 31;
            int       result = 1;

            result = prime * result + (IsSent ? 1231 : 1237);
            result = prime * result + ((Message == null) ? 0 : Message.GetHashCode());
            result = prime * result + ((Msisdn == null) ? 0 : Msisdn.GetHashCode());
            result = prime * result + MessageStatus.GetHashCode();
            result = prime * result + (int)(Timestamp ^ (Convert.ToUInt32(Timestamp) >> 32));
            return(result);
        }
Exemplo n.º 8
0
        public override bool Equals(Object obj)
        {
            if (this == obj)
            {
                return(true);
            }
            if (obj == null)
            {
                return(false);
            }
            if (GetType() != obj.GetType())
            {
                return(false);
            }
            ConvMessage other = (ConvMessage)obj;

            if (IsSent != other.IsSent)
            {
                return(false);
            }
            if (Message == null)
            {
                if (other.Message != null)
                {
                    return(false);
                }
            }
            else if (Message.CompareTo(other.Message) != 0)
            {
                return(false);
            }
            if (Msisdn == null)
            {
                if (other.Msisdn != null)
                {
                    return(false);
                }
            }
            else if (Msisdn.CompareTo(other.Msisdn) != 0)
            {
                return(false);
            }
            if (MessageStatus.Equals(other.MessageStatus))
            {
                return(false);
            }
            if (Timestamp != other.Timestamp)
            {
                return(false);
            }
            return(true);
        }
Exemplo n.º 9
0
        private static Router GetSmsRoute(ICorrespondent source, ICorrespondent target)
        {
            var sourceMobileNumber = source.MobileNumber;

            if (string.IsNullOrWhiteSpace(sourceMobileNumber))
            {
                // For sms the source is not that important
                sourceMobileNumber = "0";
            }

            var targetMobileNumber = target.MobileNumber;

            if (!Msisdn.IsValid(targetMobileNumber, Country))
            {
                return(null);
            }

            var msisdn = new Msisdn(targetMobileNumber, Country);

            return(new Router {
                Source = sourceMobileNumber, Target = msisdn.ToString(Msisdn.Format.International)
            });
        }
 /// <summary>
 /// Instantiates a new <see cref="SwishPaymentSaleTransaction"/> with the provided <paramref name="msisdn"/>.
 /// </summary>
 /// <param name="msisdn">The payers <seealso cref="Msisdn"/>.</param>
 public SwishPaymentSaleTransaction(Msisdn msisdn)
 {
     Msisdn = msisdn;
 }
 /// <summary>
 /// Constructs a new object holding a payers shipping details.
 /// </summary>
 /// <param name="email">The payers email.</param>
 /// <param name="msisdn">The payers MSISDN.</param>
 /// <param name="shippingAddress">The payers shippingaddress.</param>
 public ShippingDetails(EmailAddress email, Msisdn msisdn, Address shippingAddress)
 {
     Email           = email;
     Msisdn          = msisdn;
     ShippingAddress = shippingAddress;
 }
Exemplo n.º 12
0
        public List <Msisdn> execute()
        {
            List <Msisdn>            Envelopes        = new List <Msisdn>();
            List <string>            Table_Header     = new List <string>();
            Dictionary <int, string> Exp_Table_Header = new Dictionary <int, string>();
            string Right_Message = "";

            if (this.ExcelFileName != "")
            {
                Excel.Application xlapp = new Excel.Application();
                Excel.Workbook    xlwb  = xlapp.Workbooks.Open(this.ExcelFileName);
                Excel.Worksheet   xlws  = (Excel.Worksheet)xlwb.Worksheets.get_Item(1);
                Excel.Range       range = xlws.UsedRange;

                // Add Header to Table_Header array
                foreach (int i in Enumerable.Range(1, range.Columns.Count))
                {
                    Table_Header.Add(Convert.ToString((range.Cells[1, i] as Excel.Range).Value2));
                }

                // Add Expression to Exp_Table_Header Dictionary
                int Y = 0;
                foreach (var item in Table_Header)
                {
                    Exp_Table_Header[Y] = string.Format("[c{0}:{1}]", Y, item);
                    Y += 1;
                }
                foreach (int i in Enumerable.Range(1, range.Rows.Count))
                {
                    Right_Message = this.MessageTemplate;
                    foreach (KeyValuePair <int, string> item in Exp_Table_Header)
                    {
                        int    K = item.Key;
                        string V = item.Value;
                        Right_Message = Right_Message.Replace(V, Convert.ToString((range.Cells[i, K + 1] as Excel.Range).Value2));
                    }
                    string number  = Convert.ToString((range.Cells[i, this.ExcelPhoneColumn] as Excel.Range).Value2);
                    string gsm_num = "";
                    if (Utils.is_number(number))
                    {
                        gsm_num = Utils.clean_phone(number);
                    }
                    else
                    {
                        continue;
                    }
                    int pos = Array.IndexOf(this.GSM_Array, gsm_num);
                    if (pos > -1)
                    {
                        Msisdn msisdn = new Msisdn(gsm_num, Right_Message);
                        Envelopes.Add(msisdn);
                    }
                }
                xlwb.Close(true, null, null);
                xlapp.Quit();

                ReleaseOBJ.releaseObject(xlws);
                ReleaseOBJ.releaseObject(xlwb);
                ReleaseOBJ.releaseObject(xlapp);
            }
            return(Envelopes);
        }
Exemplo n.º 13
0
        public IHttpActionResult Post([FromBody] UserModel model)
        {
            if (!Msisdn.IsValid(model.MobileNumber, Country))
            {
                return(this.BadRequestEx(Error.MobileNumberInvalid));
            }

            using (var dbContext = new DataContext())
            {
                var user = new User();
                user.FirstName        = model.FirstName;
                user.LastName         = model.LastName;
                user.Email            = model.Email;
                user.MobileNumber     = model.MobileNumber;
                user.Status           = Data.Enums.Status.Active;
                user.CreatedTimestamp = DateTime.Now;
                user.IsOfficer        = model.IsOfficer ? "1" : "0";
                user.ExternalID       = model.ExternalID;

                dbContext.Users.Add(user);

                if (model.Districts != null)
                {
                    foreach (var districtModel in model.Districts)
                    {
                        var district = dbContext.Districts.Find(districtModel.ID);
                        if (district == null)
                        {
                            continue;
                        }

                        var userDistrict = new UserDistrict();
                        userDistrict.District = district;
                        userDistrict.User     = user;

                        dbContext.UserDistricts.Add(userDistrict);
                    }
                }

                var userName = Kapsch.Core.Cryptography.Random.GenerateConcatenatedString(model.FirstName.Substring(0, 1), model.LastName);
                while (true)
                {
                    if (!dbContext.Credentials.Any(f => f.UserName == userName))
                    {
                        break;
                    }

                    userName = Kapsch.Core.Cryptography.Random.GenerateConcatenatedString(model.FirstName.Substring(0, 1), model.LastName);
                }

                Random random = new Random();

                var credential = new Credential();
                credential.CreatedTimeStamp = DateTime.Now;
                credential.EntityID         = user.ID;
                credential.EntityType       = Data.Enums.EntityType.User;
                credential.ExpiryTimeStamp  = DateTime.Now.AddYears(20);
                credential.Status           = Data.Enums.Status.Active;
                credential.UserName         = userName;

                credential.Password = Membership.GeneratePassword(8, 0);
                credential.Password = Regex.Replace(credential.Password, @"[^a-zA-Z0-9]", m => random.Next(0, 9).ToString());

                dbContext.Credentials.Add(credential);

                if (model.SystemFunctions != null)
                {
                    foreach (var systemFunctionModel in model.SystemFunctions)
                    {
                        var systemFunction = dbContext.SystemFunctions.Find(systemFunctionModel.ID);
                        if (systemFunction == null)
                        {
                            continue;
                        }

                        var userSystemFunction = new CredentialSystemFunction();
                        userSystemFunction.SystemFunction = systemFunction;
                        userSystemFunction.Credential     = credential;
                        userSystemFunction.Status         = Data.Enums.Status.Active;

                        dbContext.CredentialSystemFunctions.Add(userSystemFunction);
                    }
                }

                dbContext.SaveChanges();

                var logo = string.Format("{0}/Images/IMS-logo-180x66-1color.png", UserManagementPortal);

                var personalizations = new Dictionary <string, string>();
                personalizations.Add("website", UserManagementPortal);
                personalizations.Add("logo", logo);
                personalizations.Add("fullName", string.Format("{0} {1}", user.FirstName, user.LastName));
                personalizations.Add("userName", credential.UserName);
                personalizations.Add("password", credential.Password);

                //EmailHelper.Send(
                //    HttpContext.Current.Server.MapPath("~/MailTemplates"),
                //    new[] { model.Email },
                //    "Account Created",
                //    "AccountCreated.txt",
                //    personalizations);
                var company = dbContext.Companies.FirstOrDefault(f => f.Name == "Intelligent Mobility Solutions"); // IMS
                if (company == null)
                {
                    Elmah.ErrorSignal.FromCurrentContext().Raise(new Exception("Unable to get company, Intelligent Mobility Solutions, from database."));
                }
                else
                {
                    SmsHelper.Send(
                        dbContext,
                        "User Management",
                        "Create User",
                        new Router()
                    {
                        Source = "IMS", Target = new Msisdn(user.MobileNumber, Country).ToString(Msisdn.Format.International)
                    },
                        company,
                        user,
                        HttpContext.Current.Server.MapPath("~/MailTemplates"),
                        "SmsAccountCreated.txt",
                        personalizations);
                }

                model.ID               = user.ID;
                model.UserName         = credential.UserName;
                model.Status           = (Models.Enums.UserStatus)user.Status;
                model.CreatedTimestamp = user.CreatedTimestamp;

                return(Ok(model));
            }
        }
Exemplo n.º 14
0
 /// <summary>
 /// Instantiates a new <see cref="PrefillInfo"/> using the provided <paramref name="msisdn"/>.
 /// </summary>
 /// <param name="msisdn">The payers phone number to pre-fill in the payment window.</param>
 public PrefillInfo(Msisdn msisdn)
 {
     Msisdn = msisdn;
 }
Exemplo n.º 15
0
 /// <summary>
 /// Instantiates a new <see cref="BillingDetails"/> with the provided parameters.
 /// </summary>
 /// <param name="email">The consumers email address.</param>
 /// <param name="msisdn">The consumers MSISDN.</param>
 /// <param name="billingAddress">The consumers billing address.</param>
 public BillingDetails(EmailAddress email, Msisdn msisdn, Address billingAddress)
 {
     Email          = email;
     Msisdn         = msisdn;
     BillingAddress = billingAddress;
 }
Exemplo n.º 16
0
 public virtual ConsumersRequest GetConsumerResourceRequest(Language language,
                                                            IEnumerable <RegionInfo> shippingAddressRestrictedToCountryCodes, EmailAddress email = null,
                                                            Msisdn msisdn = null, NationalIdentifier nationalIdentifier = null)
 {
     return(new ConsumersRequest(language, shippingAddressRestrictedToCountryCodes, Operation.Initiate));
 }
Exemplo n.º 17
0
 /// <summary>
 /// Instantiates a new <see cref="SwishPaymentSaleRequest"/> with the provided <paramref name="msisdn"/>.
 /// </summary>
 /// <param name="msisdn">The payers <seealso cref="Msisdn"/>.</param>
 public SwishPaymentSaleRequest(Msisdn msisdn)
 {
     Transaction = new SwishPaymentSaleTransaction(msisdn);
 }
Exemplo n.º 18
0
        public IHttpActionResult Put([FromBody] UserModel model)
        {
            if (!Msisdn.IsValid(model.MobileNumber, Country))
            {
                return(this.BadRequestEx(Error.MobileNumberInvalid));
            }

            using (var dbContext = new DataContext())
            {
                var credential = dbContext.Credentials
                                 .Include(f => f.User)
                                 .Include(f => f.CredentialSystemFunctions)
                                 .SingleOrDefault(f => f.EntityID == model.ID && f.EntityType == Data.Enums.EntityType.User);
                if (credential == null)
                {
                    return(this.BadRequestEx(Error.UserDoesNotExist));
                }

                User user = credential.User;
                user.FirstName    = model.FirstName;
                user.LastName     = model.LastName;
                user.Email        = model.Email;
                user.MobileNumber = model.MobileNumber;
                user.Status       = (Data.Enums.Status)model.Status;
                user.IsOfficer    = model.IsOfficer ? "1" : "0";
                user.ExternalID   = model.ExternalID;

                credential.CredentialSystemFunctions.ToList().ForEach(f => dbContext.CredentialSystemFunctions.Remove(f));
                foreach (var systemFunctionModel in model.SystemFunctions)
                {
                    var systemFunction = dbContext.SystemFunctions.Find(systemFunctionModel.ID);
                    if (systemFunction == null)
                    {
                        continue;
                    }

                    var userSystemFunction = new CredentialSystemFunction();
                    userSystemFunction.SystemFunction = systemFunction;
                    userSystemFunction.Credential     = credential;
                    userSystemFunction.Status         = Data.Enums.Status.Active;

                    dbContext.CredentialSystemFunctions.Add(userSystemFunction);
                }

                user.UserDistricts.ToList().ForEach(f => dbContext.UserDistricts.Remove(f));
                foreach (var districtModel in model.Districts)
                {
                    var district = dbContext.Districts.Find(districtModel.ID);
                    if (district == null)
                    {
                        continue;
                    }

                    var userDistrict = new UserDistrict();
                    userDistrict.District = district;
                    userDistrict.User     = user;

                    dbContext.UserDistricts.Add(userDistrict);
                }

                dbContext.SaveChanges();

                return(Ok());
            }
        }