Beispiel #1
0
        public void UpdateUser(UserModel user, Guid currentUserId)
        {
            using (var _db = new CoreEntities())
            {
                using (var dbContextTransaction = _db.Database.BeginTransaction())
                {
                    try
                    {
                        _db.User_Update(user.UserId, user.FirstName, user.LastName, user.MiddleName, user.DateOfBirth, user.PlaceOfBirth, currentUserId);

                        if (user.Address != null && user.Address.Count > 0)
                        {
                            foreach (var add in user.Address)
                            {
                                _db.Address_Update(add.Id, add.Address1, add.Address2, add.City, add.State, add.Zip, add.Country);
                            }
                        }
                        if (user.Emails != null)
                        {
                            foreach (var email in user.Emails)
                            {
                                _db.Email_Update(email.EmailId, email.EmailAddress, email.EmailType, true);
                            }
                        }
                        if (user.Phones != null)
                        {
                            foreach (var phone in user.Phones)
                            {
                                if (phone.PhoneId == Guid.Empty)
                                {
                                    _db.User_Add_Phone(user.UserId, currentUserId, Guid.NewGuid(), phone.PhoneNumber, phone.PhoneType, phone.Description);
                                }
                                else
                                {
                                    _db.Phone_Update(phone.PhoneId, phone.PhoneNumber, phone.Description, phone.PhoneType);
                                }
                            }
                        }

                        /*
                         *
                         * if (user.Occupations != null)
                         * {
                         *  foreach (var oc in user.Occupations)
                         *  {
                         *      _db.User_Add_Occupation(user.UserId, currentUserId, Guid.NewGuid(), oc, "", DateTime.Now, DateTime.Now, true);
                         *  }
                         * }
                         */
                        dbContextTransaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        dbContextTransaction.Rollback();
                    }
                }
            }
        }
Beispiel #2
0
        public void ClearTest()
        {
            Effort.Provider.EffortProviderConfiguration.RegisterProvider();
            var Connection = ConfigurationManager.ConnectionStrings["CoreEntities"];

            connection = Effort.EntityConnectionFactory.CreateTransient(Connection.ConnectionString);
            context    = new CoreEntities(connection);
            InitializeSeed();
        }
Beispiel #3
0
        public static AuthenticationResult Authenticate(string userName, string password, out Account account, bool passwordIsHashed = false)
        {
            if (string.IsNullOrWhiteSpace(userName))
            {
                throw new ArgumentNullException("userName");
            }

            if (string.IsNullOrWhiteSpace(password))
            {
                throw new ArgumentNullException("password");
            }

            int authenticationAttemptID = 0;
            AuthenticationStatus result = AuthenticationStatus.Failure_Unknown;

            using (ICoreRepositoryManager repository = CoreServiceLocator.GetRepositoryManager())
            {
                CoreEntities ctx = repository.DataModel;
                account = null;

                //lets patch up the username and remove any leading or trailing spaces.
                userName = userName.Trim();

                //lets look and see if the userName is an email address.
                account = ctx.Accounts.SingleOrDefault(p => p.UserName == userName && !p.Voided);

                if (account != null)
                {
                    //check account approved/disabled
                    result = account.Approved ? AuthenticationStatus.Success : AuthenticationStatus.Failure_AccountNotApproved;
                    result = account.Disabled ? AuthenticationStatus.Failure_AccountDisabled : AuthenticationStatus.Success;
                    result = account.Password == null ? AuthenticationStatus.Failure_NoPassword : AuthenticationStatus.Success;

                    //if so far we are approved and not disabled, and password is not null, then lets check the password against the input.
                    if (result == AuthenticationStatus.Success && !VerifyPasswordMatch(password, account.Password, passwordIsHashed))
                    {
                        result = AuthenticationStatus.Failure_IncorrectPassword;
                    }
                }
                else
                {
                    result = AuthenticationStatus.Failure_AccountNotExist;
                }

                if (account != null)
                {
                    //detach the contact so we don't have to worry about duplicates being committed into the database since this context is going out of scope *very* soon.
                    ctx.Detach(account);
                }
            }

            return(new AuthenticationResult(result, authenticationAttemptID));
        }
Beispiel #4
0
 public SolicitudController()
 {
     if (core == null)
     {
         core = new CoreEntities(_ctx);
     }
     if (coreDetail == null)
     {
         coreDetail = new DetalleSolicitudCore(_ctx);
     }
     if (coreAuto == null)
     {
         coreAuto = new AutosCore(_ctx);
     }
 }
 public RoleService(ContextContainer Context)
 {
     this.Context = Context;
     db           = Context.CoreEntities;
 }
Beispiel #6
0
        public List <UserModel> GetUsers(PostUsersRequest req, Guid currentUser)
        {
            var users = new List <UserModel>();

            using (var _db = new CoreEntities())
            {
                users = (from u in _db.User_Get(req.FirstName, req.LastName, null, null, null, null, null, currentUser)
                         select UsersAdapter.ToClientUser(u)).ToList();

                foreach (var user in users)
                {
                    var addresses = (from a in _db.UserAddress_GET(user.UserId)
                                     where a != null
                                     select AddressAdapter.toServiceAddress(a)
                                     ).ToList();
                    foreach (var ad in addresses)
                    {
                        if (ad != null)
                        {
                            user.Address.Add(ad);
                        }
                    }
                    var emails = (from e in _db.Email_Get(user.UserId)
                                  where e != null && e.Id != null
                                  select new Email()
                    {
                        EmailAddress = e.Email,
                        EmailType = e.EmailType,
                        EmailId = (Guid)e.Id
                    }).ToList();
                    foreach (var em in emails)
                    {
                        if (em != null)
                        {
                            user.Emails.Add(em);
                        }
                    }

                    var phones = (from ph in _db.Phone_Get(user.UserId)
                                  where ph != null && ph.Id != null
                                  select new Phone()
                    {
                        PhoneId = (Guid)ph.Id,
                        Description = ph.PhoneDescription,
                        PhoneNumber = ph.PhoneNumber,
                        PhoneType = ph.PhoneType,
                        IsPrimaryPhone = true
                    }).ToList();
                    foreach (var ph in phones)
                    {
                        if (ph != null)
                        {
                            user.Phones.Add(ph);
                        }
                    }
                    var ChildrenRelations = (from r in _db.UserRelations_Get(user.UserId, null)
                                             select new UserRelation()
                    {
                        ToUserId = (Guid)r.ToUserId,
                        FromUserId = (Guid)r.FromUserId,
                        Type = r.RelationType
                    }).ToList();
                    foreach (var ch in ChildrenRelations)
                    {
                        ch.User = (from u in _db.User_Get(null, null, null, null, null, null, ch.ToUserId, currentUser)
                                   select UsersAdapter.ToClientUser(u)).FirstOrDefault();
                        user.Relations.Add(ch);
                    }

                    var parentsRelations = (from r in _db.UserRelations_Get(null, user.UserId)
                                            select new UserRelation()
                    {
                        ToUserId = (Guid)r.ToUserId,
                        FromUserId = (Guid)r.FromUserId,
                        Type = r.RelationType
                    }).ToList();

                    foreach (var prt in parentsRelations)
                    {
                        prt.User = (from u in _db.User_Get(null, null, null, null, null, null, prt.FromUserId, currentUser)
                                    select UsersAdapter.ToClientUser(u)).FirstOrDefault();
                        user.Relations.Add(prt);
                    }
                }
            }
            return(users);
        }
        //protected ILog log;

        public BaseController()
        {
            CoreContext = CoreEntities.Create();
            CoreContext.Configuration.ProxyCreationEnabled = false;
            Context = new ContextContainer();
        }