Example #1
0
        public static bool CustomerExists(Customer customer)
        {
            try
            {
                var existingCustomer = new Customer();
                using (var context = new KioskWebDBEntities())
                {
                    existingCustomer = context.Customers
                                    .Where(t => t.EmailAddress.Equals(customer.EmailAddress))
                                    .FirstOrDefault();
                }

                if (existingCustomer == null)
                    return false;
                else
                    return true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #2
0
 public static bool Save(Customer customer, out string message)
 {
     try
     {
         if (CustomerDL.CustomerExists(customer))
         {
             message = string.Format("Customer with email address: {0} exists already", customer.EmailAddress);
             return false;
         }
         else
         {
             message = string.Empty;
             return CustomerDL.Save(customer);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Example #3
0
 public static bool Update(Customer customer)
 {
     try
     {
         return CustomerDL.Update(customer);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Example #4
0
        public static bool Update(Customer customer)
        {
            try
            {
                Customer existingCustomer = new Customer();
                using (var context = new KioskWebDBEntities())
                {
                    existingCustomer = context.Customers
                                    .Where(t => t.ID == customer.ID)
                                    .FirstOrDefault();
                }

                if (existingCustomer != null)
                {
                    existingCustomer.Lastname = customer.Lastname;
                    existingCustomer.Othernames = customer.Othernames;
                    existingCustomer.EmailAddress = customer.EmailAddress;
                    existingCustomer.PhoneNumber = customer.PhoneNumber;

                    using (var context = new KioskWebDBEntities())
                    {
                        context.Entry(existingCustomer).State = EntityState.Modified;

                        context.SaveChanges();
                    }

                    return true;
                }
                else
                {
                    return false;
                }

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #5
0
 public static bool Save(Customer customer)
 {
     try
     {
         using (var context = new KioskWebDBEntities())
         {
             context.Customers.Add(customer);
             context.SaveChanges();
         }
         return true;
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Example #6
0
        public static void SendCardRequestToken(Customer customer, string token)
        {
            try
            {

                string userFullName = customer.Lastname + " " + customer.Othernames;
                string organization = System.Configuration.ConfigurationManager.AppSettings.Get("Organization");
                string applicationName = System.Configuration.ConfigurationManager.AppSettings.Get("ApplicationName");
                string subject = "Welcome to " + applicationName;
                string fromAddress = "";
                string smtpUsername = "";
                string smtpPassword = "";
                string smtpHost = "";
                Int32 smtpPort = 587;
                bool smtpUseDefaultCredentials = false;
                bool smtpEnableSsl = true;

                MailHelper mailConfig = ConfigurationManager.GetSection("mailHelperSection") as MailHelper;
                if (mailConfig != null && mailConfig.Mail != null)
                {
                    fromAddress = mailConfig.Mail.FromEmailAddress;
                    smtpUsername = mailConfig.Mail.Username;
                    smtpPassword = mailConfig.Mail.Password;
                }

                if (mailConfig != null && mailConfig.Smtp != null)
                {
                    smtpHost = mailConfig.Smtp.Host;
                    smtpPort = Convert.ToInt32(mailConfig.Smtp.Port);
                    smtpUseDefaultCredentials = Convert.ToBoolean(mailConfig.Smtp.UseDefaultCredentials);
                    smtpEnableSsl = Convert.ToBoolean(mailConfig.Smtp.EnableSsl);
                }

                string body = "";

                body = System.IO.File.ReadAllText(System.Web.Hosting.HostingEnvironment.MapPath(@"~/App_Data/MailTemplates/CardRequest.txt"));
                body = body.Replace("#Organization", organization);
                body = body.Replace("#ApplicationName", applicationName);
                body = body.Replace("#UserFullName", userFullName);
                body = body.Replace("#Token", token);

                Thread email = new Thread(delegate()
                {
                    Mail.SendMail(customer.EmailAddress, fromAddress, subject, body, smtpHost, smtpPort, smtpUseDefaultCredentials, smtpUsername, smtpPassword, smtpEnableSsl);

                });

                email.IsBackground = true;
                email.Start();

            }
            catch (Exception ex)
            {
                ErrorHandler.WriteError(ex);
                throw ex;
            }
        }