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); }
public bool SetCustomerRequestInfo(GetQuoteInfo inf, HappyHutDataBaseEntities Entities = null) { bool bFlag = false; DateTime now = DateTime.UtcNow; HappyHutDataBaseEntities entities = null; try { entities = Entities == null ? new HappyHutDataBaseEntities() : Entities; GetQuoteRequest dat = entities.GetQuoteRequests.SingleOrDefault(x => x.Id.Equals(inf.Id)); if (dat == null) { dat = new GetQuoteRequest() { Id = Guid.NewGuid(), CreateDt = now, }; entities.GetQuoteRequests.Add(dat); } dat.FirstName = !String.IsNullOrEmpty(inf.FirstName) ? inf.FirstName : String.Empty; dat.LastName = !String.IsNullOrEmpty(inf.LastName) ? inf.LastName : String.Empty; dat.Email = !String.IsNullOrEmpty(inf.Email) ? inf.Email : String.Empty; dat.MobileNumber = !String.IsNullOrEmpty(inf.MobileNumber) ? inf.MobileNumber : String.Empty; dat.ServiceId = inf.ServiceId; dat.IsEmailSent = inf.IsEmailSent; dat.EmailSentDt = inf.EmailSentDt; dat.PreferredDate = inf.PreferredDate; dat.PreferredTime = inf.PreferredTime; dat.AdditionalInfo = !String.IsNullOrEmpty(inf.AdditionalInfo) ? inf.AdditionalInfo : String.Empty; 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); }