Example #1
0
        public async Task<UpdatedDemographicModel> DemographicUserGetAsync(String AspUserId)
        {
            try
            {
                ApplicationUser aspUser = await FindAspUserByUserId(AspUserId);

                UpdatedDemographicModel user = new UpdatedDemographicModel();
                Client client = new Client();

                using (WW_DevEntities context = new WW_DevEntities())
                {
                    client = context.Clients.Where(q => q.AspUserId == AspUserId).FirstOrDefault();

                    if (client != null)
                    {
                        // TODO:
                        // implement dob
                        user.FirstName = client.FirstName;
                        user.MiddleName = client.MiddleName;
                        user.LastName = client.LastName;
                        user.Suffix = client.Suffix;
                        //user.SSN = client.SSN;
                        //user.DateOfBirth = client.DateOfBirth.Value.ToShortDateString() ?? client.DateOfBirth.Value.ToShortDateString();
                        user.Email = aspUser.Email;
                    }
                }

                return user;
            }
            catch (Exception ex)
            {
                ErroLogging.LogError(ex);
                throw ex;
            }
        }
Example #2
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;
            }
        }
Example #3
0
        public async Task<IHttpActionResult> DemographicUserUpdate(UpdatedDemographicModel model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return BadRequest(ModelState);
                }

                using (AuthRepository repo = new AuthRepository())
                {
                    await repo.UpdateUserAsync(model);
                    
                    return Ok();
                }
            }
            catch (Exception ex)
            {
                Helper.ErrorLogging.LogError(ex);
                return InternalServerError(ex);
            }

        }