예제 #1
0
        private void CreateHappyHutUsers()
        {
            try
            {
                List <HappyHutUserInfo> lstHappyHutUsers = new List <HappyHutUserInfo>();
                if (lstCreateUser != null && lstCreateUser.Count > 0)
                {
                    foreach (String strEmail in lstCreateUser)
                    {
                        if (CreateUser(strEmail))
                        {
                            GetQuoteInfo quoteInfo = lstQuotes.Where(x => x.Email.ToLower().Equals(strEmail.ToLower())).FirstOrDefault();

                            EmailUtil utilObject = new EmailUtil()
                            {
                                ToEmail = strEmail,
                                ToName  = String.Format("{0} {1}", quoteInfo.FirstName, quoteInfo.LastName),
                                Subject = "Login information for HappyHut!!!",
                            };
                            //TODO:: Add Body Template
                            bool emailSent = EmailUtil.Instance.SendEmail(utilObject);
                            if (!emailSent)
                            {
                                ApplicationLog.Instance.WriteWarning(String.Format("Email not sent to {0} for service login", strEmail));
                                //TODO:: Send email to [email protected] && [email protected]
                            }

                            if (quoteInfo != null)
                            {
                                HappyHutUserInfo inf = new HappyHutUserInfo()
                                {
                                    Username     = strEmail,
                                    FirstName    = quoteInfo.FirstName,
                                    LastName     = quoteInfo.LastName,
                                    Email        = quoteInfo.Email,
                                    MobileNumber = String.Empty,
                                    AddressLine1 = String.Empty,
                                    AddressLine2 = String.Empty,
                                    CityId       = quoteInfo.CityId,
                                    IsFirstLogin = true,
                                };
                                lstHappyHutUsers.Add(inf);
                            }
                        }
                    }
                }

                if (lstHappyHutUsers != null && lstHappyHutUsers.Count > 0)
                {
                    client = new DatabaseClass();
                    client.SetHappyHutUsersInfos(lstHappyHutUsers, null);
                }
            }
            catch (Exception ex)
            {
                ApplicationLog.Instance.WriteException(ex);
            }
        }
예제 #2
0
        public bool SetHappyHutUserInfo(HappyHutUserInfo inf, HappyHutDataBaseEntities Entities = null)
        {
            bool     bFlag = false;
            DateTime now   = DateTime.UtcNow;
            HappyHutDataBaseEntities entities = null;

            try
            {
                entities = Entities == null ? new HappyHutDataBaseEntities() : Entities;
                HappyHutUser dat = entities.HappyHutUsers.SingleOrDefault(x => x.AspNetUser.UserName.ToLower().Equals(inf.Username.ToLower()));

                if (dat == null)
                {
                    dat = new HappyHutUser()
                    {
                        UserId   = entities.AspNetUsers.SingleOrDefault(x => x.UserName.ToLower().Equals(inf.Username.ToLower())).Id,
                        CreateDt = now,
                    };
                    entities.HappyHutUsers.Add(dat);
                }

                dat.FirstName    = !String.IsNullOrEmpty(inf.FirstName) ? inf.FirstName : String.Empty;
                dat.LastName     = !String.IsNullOrEmpty(inf.LastName) ? inf.LastName : String.Empty;
                dat.MobileNumber = !String.IsNullOrEmpty(inf.MobileNumber) ? inf.MobileNumber : String.Empty;
                dat.AddressLine1 = !String.IsNullOrEmpty(inf.AddressLine1) ? inf.AddressLine1 : String.Empty;
                dat.AddressLine2 = !String.IsNullOrEmpty(inf.AddressLine2) ? inf.AddressLine2 : String.Empty;
                dat.CityId       = inf.CityId;
                dat.StateId      = entities.Cities.SingleOrDefault(x => x.ID.Equals(inf.CityId)).StateId;
                dat.IsFirstLogin = inf.IsFirstLogin;
                dat.LastUpdateDt = now;

                if (Entities == null)
                {
                    entities.SaveChanges();
                }
                bFlag = true;
            }
            catch (DbEntityValidationException e)
            {
                foreach (var eve in e.EntityValidationErrors)
                {
                    ApplicationLog.Instance.WriteError(String.Format("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                                                     eve.Entry.Entity.GetType().Name, eve.Entry.State));
                    foreach (var ve in eve.ValidationErrors)
                    {
                        ApplicationLog.Instance.WriteError(String.Format("- Property: \"{0}\", Error: \"{1}\"",
                                                                         ve.PropertyName, ve.ErrorMessage));
                    }
                }
            }
            catch (Exception ex)
            {
                ApplicationLog.Instance.WriteException(ex);
            }
            finally
            {
                if (Entities == null)
                {
                    entities.Dispose();
                }
            }
            return(bFlag);
        }