public int Account_AddFromAspNetUser(string aspNetId, AppUser entity, ref string statusMessage)
        {
            EM.Account efEntity = new EM.Account();
            using (var context = new EntityContext())
            {
                try
                {
                    EM.AspNetUser user = AspNetUser_Get(entity.Email);

                    AppUser_FromMap(entity, efEntity);

                    efEntity.RowId = Guid.NewGuid();

                    efEntity.Created     = System.DateTime.Now;
                    efEntity.LastUpdated = System.DateTime.Now;

                    context.Accounts.Add(efEntity);

                    // submit the change to database
                    int count = context.SaveChanges();
                    if (count > 0)
                    {
                        statusMessage = "successful";
                        entity.Id     = efEntity.Id;

                        return(efEntity.Id);
                    }
                    else
                    {
                        //?no info on error
                        statusMessage = "Error - the add was not successful. ";
                        string message = string.Format("AccountManager. Account_Add Failed", "Attempted to add a Account. The process appeared to not work, but was not an exception, so we have no message, or no clue.Email: {0}", entity.Email);
                        EmailManager.NotifyAdmin("	Manager. Account_Add Failed", message);
                    }
                }
                catch (System.Data.Entity.Validation.DbEntityValidationException dbex)
                {
                    //LoggingHelper.LogError( dbex, thisClassName + string.Format( ".ContentAdd() DbEntityValidationException, Type:{0}", entity.TypeId ) );
                    string message = thisClassName + string.Format(".Account_Add() DbEntityValidationException, Email: {0}", efEntity.Email);
                    foreach (var eve in dbex.EntityValidationErrors)
                    {
                        message += string.Format("\rEntity 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)
                        {
                            message += string.Format("- Property: \"{0}\", Error: \"{1}\"",
                                                     ve.PropertyName, ve.ErrorMessage);
                        }

                        LoggingHelper.LogError(message, true);
                    }
                }
                catch (Exception ex)
                {
                    LoggingHelper.LogError(ex, thisClassName + string.Format(".Account_Add(), Email: {0}", efEntity.Email));
                }
            }

            return(efEntity.Id);
        }
        public static EM.AspNetUser AspNetUser_Get(string email)
        {
            EM.AspNetUser entity = new EM.AspNetUser();
            using (var context = new EntityContext())
            {
                entity = context.AspNetUsers
                         .SingleOrDefault(s => s.Email.ToLower() == email.ToLower());

                if (entity != null && entity.Email != null && entity.Email.Length > 5)
                {
                }
            }

            return(entity);
        }
        public static AppUser AppUser_GetFromAspUser(string email)
        {
            AppUser entity = new AppUser();

            using (var context = new EntityContext())
            {
                EM.AspNetUser efEntity = context.AspNetUsers
                                         .SingleOrDefault(s => s.Email.ToLower() == email.ToLower());

                if (efEntity != null && efEntity.Email != null && efEntity.Email.Length > 5)
                {
                    entity = AppUser_GetByEmail(efEntity.Email);
                }
            }

            return(entity);
        }
        public static bool AspNetUsers_Update(AppUser entity, ref string statusMessage)
        {
            using (var context = new EntityContext())
            {
                try
                {
                    EM.AspNetUser efEntity = context.AspNetUsers
                                             .SingleOrDefault(s => s.Id == entity.AspNetUserId);

                    if (efEntity != null && efEntity.UserId > 0)
                    {
                        efEntity.FirstName      = entity.FirstName;
                        efEntity.LastName       = entity.LastName;
                        efEntity.Email          = entity.Email;
                        efEntity.EmailConfirmed = true;
                        //could be dangerous, as hidden??
                        //efEntity.UserName = entity.UserName;

                        if (HasStateChanged(context))
                        {
                            // submit the change to database
                            int count = context.SaveChanges();
                            if (count > 0)
                            {
                                statusMessage = "successful";
                                return(true);
                            }
                            else
                            {
                                //?no info on error
                                statusMessage = "Error - the update was not successful. ";
                                string message = string.Format(thisClassName + ".AspNetUsers_Update Failed", "Attempted to update AspNetUsers (sync with Account). The process appeared to not work, but was not an exception, so we have no message, or no clue.Email: {0}", entity.Email);
                                EmailManager.NotifyAdmin(thisClassName + "AspNetUsers_Update Failed", message);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    LoggingHelper.LogError(ex, thisClassName + string.Format(".AspNetUsers_Update(), Email: {0}", entity.Email));
                }
            }

            return(false);
        }
        public bool AspNetUsers_UpdateEmailConfirmedByEmail(string email, ref string statusMessage)
        {
            using (var context = new EntityContext())
            {
                EM.AspNetUser efEntity = context.AspNetUsers
                                         .SingleOrDefault(s => s.Email == email);
                try
                {
                    if (efEntity != null && efEntity.UserId > 0)
                    {
                        efEntity.EmailConfirmed = true;

                        if (HasStateChanged(context))
                        {
                            // submit the change to database
                            int count = context.SaveChanges();
                            if (count > 0)
                            {
                                statusMessage = "successful";
                                return(true);
                            }
                            else
                            {
                                //?no info on error
                                statusMessage = "Error - the update of EmailConfirmed was not successful. ";
                                string message = string.Format(thisClassName + ".AspNetUsers_UpdateEmailConfirmedByEmail Failed", "Attempted to update AspNetUsers.EmailConfirmed. The process appeared to not work, but was not an exception, so we have no message, or no clue.Email: {0}", efEntity.Email);
                                EmailManager.NotifyAdmin(thisClassName + "AspNetUsers_UpdateEmailConfirmedByEmail Failed", message);
                            }
                        }
                        return(true);
                    }
                }
                catch (Exception ex)
                {
                    LoggingHelper.LogError(ex, thisClassName + string.Format(".AspNetUsers_UpdateEmailConfirmedByEmail(), Email: {0}", efEntity.Email));
                }
            }

            return(false);
        }