Exemplo n.º 1
0
        public async Task<bool> AddRefreshToken(DAL.RefreshToken token)
        {
            try
            {
                using (WW_DevEntities context = new WW_DevEntities())
                {
                    DAL.RefreshToken refreshToken = context.RefreshTokens.Where(a => a.Subject == token.Subject && a.ClientId == token.ClientId).FirstOrDefault();

                    if (refreshToken != null)
                        context.RefreshTokens.Remove(refreshToken);

                    context.RefreshTokens.Add(token);

                    return await context.SaveChangesAsync() > 0;
                }
            }
            catch (Exception ex)
            {
                ErroLogging.LogError(ex);
                throw ex;
            }
        }
Exemplo n.º 2
0
 public async Task<bool> RemoveRefreshToken(string hashedTokenId)
 {
     try
     {
         using (WW_DevEntities context = new WW_DevEntities())
         {
             DAL.RefreshToken refreshToken = context.RefreshTokens.Where(a => a.Id == hashedTokenId).FirstOrDefault();
             context.RefreshTokens.Remove(refreshToken);
             return await context.SaveChangesAsync() > 0;
         }
     }
     catch (Exception ex)
     {
         ErroLogging.LogError(ex);
         throw ex;
     }
 }
Exemplo n.º 3
0
        public async Task<bool> PasswordHistoryInsert(string AspNetUserId, string userPassword)
        {
            try
            {
                using (WW_DevEntities context = new WW_DevEntities())
                {
                    userPassword = Hash.Get(userPassword);

                    context.PasswordHistories.Add(new PasswordHistory
                    {
                        CreatedDate = DateTime.Now,
                        HashPassword = userPassword,
                        UserID = AspNetUserId

                    });

                    return await context.SaveChangesAsync() > 0;
                }
            }
            catch (Exception ex)
            {
                ErroLogging.LogError(ex);
                throw ex;
            }
        }
Exemplo n.º 4
0
        public async Task<IdentityResult> RegisterUser(UserModel userModel)
        {
            ApplicationUser user = new ApplicationUser();

            try
            {
                user = new ApplicationUser
                {
                    UserName = userModel.Email,
                    Email = userModel.Email,
                    TwoFactorEnabled = true//,
                    //PhoneNumber = userModel.MobilePhoneNumber
                };

                IdentityResult result = await UserManager.CreateAsync(user, userModel.Password);

                if (result.Succeeded)
                {
                    var roleresult = UserManager.AddToRole(user.Id, RoleType.NonClient);

                    //if (string.IsNullOrEmpty(userModel.SSN))
                    //    userModel.SSN = null;

                    using (WW_DevEntities context = new WW_DevEntities())
                    {
                        Client model = new Client
                        {
                            Id = Guid.NewGuid(),
                            AspUserId = user.Id,
                            FirstName = ProperCase.Convert(userModel.FirstName),
                            LastName = ProperCase.Convert(userModel.LastName),
                            MiddleName = ProperCase.Convert(userModel.MiddleName),
                            Suffix = ProperCase.Convert(userModel.Suffix),
                            //Gender = userModel.Gender,
                            //SSN = userModel.SSN,
                            //DateOfBirth = userModel.DateOfBirth,
                            CreatedDate = DateTime.Now
                        };

                        context.Clients.Add(model);

                        context.PasswordHistories.Add(new PasswordHistory
                        {
                            CreatedDate = DateTime.Now,
                            HashPassword = Hash.Get(userModel.Password),
                            UserID = user.Id
                        });

                        //ClientPhone mPhone = new ClientPhone();
                        //ClientPhone wPhone = new ClientPhone();
                        //ClientPhone hPhone = new ClientPhone();

                        //if (userModel.MobilePhoneNumber != null)
                        //{
                        //    mPhone.PhoneNumber = userModel.MobilePhoneNumber;
                        //    mPhone.CreatedDate = DateTime.Now;
                        //    context.ClientPhones.Add(mPhone);
                        //}

                        //if (userModel.WorkPhoneNumber != null)
                        //{
                        //    wPhone.PhoneNumber = userModel.WorkPhoneNumber;
                        //    wPhone.CreatedDate = DateTime.Now;
                        //    context.ClientPhones.Add(wPhone);
                        //}

                        //if (userModel.HomePhoneNumber != null)
                        //{
                        //    hPhone.PhoneNumber = userModel.HomePhoneNumber;
                        //    hPhone.CreatedDate = DateTime.Now;
                        //    context.ClientPhones.Add(hPhone);
                        //}

                        await context.SaveChangesAsync();

                        //if (userModel.MobilePhoneNumber != null)
                        //{

                        //    context.ClientPhoneAssociatives.Add(new ClientPhoneAssociative()
                        //    {
                        //        Id = model.Id,
                        //        ClientPhoneId = mPhone.Id,
                        //        PhoneTypeId = Guid.Parse(Config.MobilePhoneType),
                        //        CreatedDate = DateTime.Now
                        //    });
                        //}

                        //if (userModel.WorkPhoneNumber != null)
                        //{
                        //    context.ClientPhoneAssociatives.Add(new ClientPhoneAssociative()
                        //    {
                        //        Id = model.Id,
                        //        ClientPhoneId = wPhone.Id,
                        //        PhoneTypeId = Guid.Parse(Config.WorkPhoneType),
                        //        CreatedDate = DateTime.Now
                        //    });
                        //}

                        //if (userModel.HomePhoneNumber != null)
                        //{
                        //    context.ClientPhoneAssociatives.Add(new ClientPhoneAssociative()
                        //    {
                        //        Id = model.Id,
                        //        ClientPhoneId = hPhone.Id,
                        //        PhoneTypeId = Guid.Parse(Config.HomePhoneType),
                        //        CreatedDate = DateTime.Now
                        //    });
                        //}

                        //await context.SaveChangesAsync();

                        await SendConfirmationEmail(user.Id, EmailMessage.NewAccountEmailConfirmation);
                    }
                }

                return result;
            }
            catch (Exception ex)
            {
                //if error on creating address and phone need to remove login             
                UserManager.Delete(user);
                ErroLogging.LogError(ex);
                throw ex;
            }
        }
Exemplo n.º 5
0
        public async Task UpdateUserAsync(UpdatedDemographicModel model)
        {
            try
            {
                using (WW_DevEntities context = new WW_DevEntities())
                {
                    ApplicationUser user = await FindAspUserByUserId(HttpContext.Current.User.Identity.Name);

                    if (user != null)
                    {
                        Client updatedUser = context.Clients.Where(q => q.AspUserId == user.Id).FirstOrDefault();

                        if (updatedUser != null)
                        {
                            updatedUser.FirstName = ProperCase.Convert(model.FirstName);
                            updatedUser.MiddleName = ProperCase.Convert(model.MiddleName);
                            updatedUser.LastName = ProperCase.Convert(model.LastName);
                            updatedUser.Suffix = ProperCase.Convert(model.Suffix);
                            //updatedUser.SSN = String.IsNullOrWhiteSpace(model.Identification.Ssn) ? null : model.Identification.Ssn;
                            //updatedUser.DateOfBirth = model.BirthInfo.DateOfBirth;
                            //updatedUser.Gender = model.Appearance.Gender;
                            updatedUser.UpdatedDate = DateTime.Now;

                            //var phoneQuery = (from pAss in context.ClientPhoneAssociatives
                            //                  join p in context.ClientPhones
                            //                  on pAss.ClientPhoneGenID equals p.ClientPhoneGenID
                            //                  join pType in context.ref_PhoneTypes
                            //                  on pAss.PhoneTypeID equals pType.PhoneTypeGenId
                            //                  where pAss.ClientGenID == updatedUser.Id
                            //                  select new
                            //                  {
                            //                      PhoneId = p.ClientPhoneGenID,
                            //                      PhoneNumber = p.PhoneNumber,
                            //                      PhoneTypeID = pAss.PhoneTypeID,
                            //                      PhoneType = pType.PhoneTypeDescription
                            //                  }).ToList();


                            //if (phoneQuery.Any())
                            //{
                            //    foreach (var p in phoneQuery)
                            //    {
                            //        if (p.PhoneTypeID == 1)
                            //        {
                            //            var updatedPhone = context.ClientPhones.Where(q => q.ClientPhoneGenID == p.PhoneId).FirstOrDefault();
                            //            updatedPhone.PhoneNumber = model.Phone.WorkPhone;
                            //        }
                            //        else if (p.PhoneTypeID == 2)
                            //        {
                            //            var updatedPhone = context.ClientPhones.Where(q => q.ClientPhoneGenID == p.PhoneId).FirstOrDefault();
                            //            updatedPhone.PhoneNumber = model.Phone.HomePhone;
                            //        }
                            //        else if (p.PhoneTypeID == 3)
                            //        {
                            //            var updatedPhone = context.ClientPhones.Where(q => q.ClientPhoneGenID == p.PhoneId).FirstOrDefault();
                            //            updatedPhone.PhoneNumber = model.Phone.MobilePhone;
                            //        }
                            //    }
                            //}

                            //if (model.Phone.MobilePhone != null)
                            //{
                            //    user.PhoneNumber = model.Phone.MobilePhone;
                            //    UserManager.Update(user);
                            //}

                            if (await context.SaveChangesAsync() > 0)
                                await SendNotificationEmail(user.Id, EmailMessage.NotificationUpdateDemographic);
                        }
                    }
                }
            }
            catch (DbEntityValidationException ex)
            {
                // Retrieve the error messages as a list of strings.
                var errorMessages = ex.EntityValidationErrors
                        .SelectMany(x => x.ValidationErrors)
                        .Select(x => x.ErrorMessage);

                // Join the list to a single string.
                var fullErrorMessage = string.Join("; ", errorMessages);

                // Combine the original exception message with the new one.
                var exceptionMessage = string.Concat(ex.Message, " The validation errors are: ", fullErrorMessage);

                ErroLogging.LogError(ex);
                // Throw a new DbEntityValidationException with the improved exception message.
                throw new DbEntityValidationException(exceptionMessage, ex.EntityValidationErrors);
            }
            catch (Exception ex)
            {
                ErroLogging.LogError(ex);
                throw ex;
            }
        }
Exemplo n.º 6
0
 public async Task MarkLogInDateTime(string AspUserId)
 {
     using (WW_DevEntities context = new WW_DevEntities())
     {
         Client currentUser = context.Clients.Where(a => a.AspUserId == AspUserId).FirstOrDefault();
         currentUser.LastLogInDate = DateTime.Now;
         await context.SaveChangesAsync();
     }
 }