public void AddStatistics(User user, SearchResultMessageEntity messageEntity, string userAgent, string imei, string model, string osVersion)
        {
            var insertTime = DateTime.Now;

            int? userId = user != null ? user.Id : (int?) null;

            if (messageEntity.Products != null)
            {
                
                foreach (var product in messageEntity.Products)
                {
                    AddProductRequest(userId, product.Id, userAgent, imei, model, osVersion);   
                }
            }

            if (messageEntity.Ingredients != null)
            {
                
                foreach (var ingredient in messageEntity.Ingredients)
                {
                    AddIngredienRequest(userId, ingredient.Id, userAgent, imei, model, osVersion);
                }
            }

            if (messageEntity.Brands != null)
            {
                foreach (var brand in messageEntity.Brands)
                {
                    AddBrandRequest(userId, brand.Id, userAgent, imei, model, osVersion);
                }
            }

            if (messageEntity.Companies != null)
            {
                
                foreach (var company in messageEntity.Companies)
                {
                    AddCompanyRequest(userId, company.Id, userAgent, imei, model, osVersion);
                }
            }

            if (messageEntity.Countries != null)
            {

                foreach (var country in messageEntity.Countries)
                {
                    AddCountryRequest(userId, country.Id, userAgent, imei, model, osVersion);
                }
            }

            if (messageEntity.Concepts != null)
            {

                foreach (var concept in messageEntity.Concepts)
                {
                    AddConceptRequest(userId, concept.Id, userAgent, imei, model, osVersion);
                }
            }
        }
        public User PersistNewUser(User user)
        {
            _userRepository.Add(user);
            _userRepository.Persist();
            
            Log.Debug("Adding and Persisting new user");

            return user;
        }
        public ShopgunMembershipWebserviceGateway CreateUser(string username, string password, string email)
        {
            ShopgunMembershipWebserviceGateway response = new ShopgunMembershipWebserviceGateway();
           
            User newUser = new User
                               {
                                   UserName = username,
                                   Password = password,
                                   Email = email,
                                   CreationDate = DateTime.Now,
                                   LastActivity = DateTime.Now,
                                   LastLockedOutDate = DateTime.Now,
                                   LastLoginDate = DateTime.Now,
                                   LastPasswordChangedDate = DateTime.Now
                               };

            //TODO: Shall support language, translate from resource string.

            //Refactoring here please, extract to a method: ValidateNewUserInfo(string username, string password, string email) : bool
            if ((newUser.UserName == null) || (newUser.Password == null))
            {
                response.value = false;
                response.message = "Enter username and password!";
                return response;
            }
            if (_membershipProviderApplicationService.GetUser(newUser.UserName, false, ProviderName) != null)
            {
                response.value = false;
                response.message = "Username already exists!";
                return response;

            }
            if (_membershipProviderApplicationService.GetUserByMail(newUser.Email, ProviderName) != null)
            {
                response.value = false;
                response.message = "Email already exists!";
                return response;
            }
            //End of refactoring

            try
            {
                _membershipProviderApplicationService.CreateUser(newUser);
                response = ValidateMobileUser(newUser.UserName, password);
                if (response.value)
                {
                    response.message = "User created!";   
                }
                return response;
            }
            catch
            {
                response.value = false;
                response.message = "User not created, system error!";
                return response;
            }
        }
Beispiel #4
0
        public ActionResult CreateUser(User newUser, FormCollection formCollection)
        {
            try
            {
                _membershipProviderApplicationService.CreateUser(newUser);

                var roles = formCollection["Roles"].Replace("false","").Split(new[]{","}, StringSplitOptions.RemoveEmptyEntries);
                foreach (var role in roles)
                {
                    _roleProviderApplicationService.AddUserToRole(newUser.UserName, role);
                }

                return RedirectToAction("Index");
            }
            catch
            {
                return RedirectToAction("CreateUser");
            }
        }
        protected override void Before_all_specs()
        {
            SetupDatabase(ShopGunSpecBase.Database.ShopGun, typeof(Base).Assembly);
            _statisticsDomainService = new StatisticsDomainService(new Repository<Brand>(GetNewDataContext()),
                                                                   new Repository<Company>(GetNewDataContext()),
                                                                   new Repository<Country>(GetNewDataContext()),
                                                                   new Repository<Product>(GetNewDataContext()),
                                                                   new Repository<Ingredient>(GetNewDataContext()),
                                                                   new Repository<Concept>(GetNewDataContext()),
                                                                   new Repository<AdviceBase>(GetNewDataContext()));

            _productBuilder = new ProductBuilder();
            _product = ProductBuilder.BuildProduct();
            _user = UserBuilder.BuildUser();
            using (var dataContext = GetNewDataContext())
            {
                dataContext.GetTable<Product>().InsertOnSubmit(_product);
                dataContext.GetTable<User>().InsertOnSubmit(_user);
                dataContext.SubmitChanges();
            }
            _searchResultMessageEntity = new SearchResultMessageEntity {Products = new List<Product> {_product}};
            base.Before_all_specs();
        }
        //extensions
        public User ToUser()
        {
            //
            User user = new User
                            {
                                Id = UserId,
                                UserName = UserName,
                                Password = Password,
                                Email = Email,
                                FirstName = FirstName,
                                LastName = LastName,
                                CreationDate = CreationDate,
                                DisplayName = DisplayName,
                                IsLockedOut = IsLockedOut,
                                LastActivity = LastActivityDate,
                                LastLockedOutDate = LastLockoutDate,
                                LastLoginDate = LastLoginDate,
                                LastPasswordChangedDate = LastPasswordChangedDate,
                                MentorId = Mentor != null ? Mentor.Id : (int?) null,
                                Mentor = Mentor
                            };

            return user;   
         }
Beispiel #7
0
        public ActionResult EditUser(User updatedUser, FormCollection formCollection)
        {
            try
            {
                _membershipProviderApplicationService.UpdateUser(updatedUser, false);

                var updatedRoles = formCollection["Roles"].Replace("false", "").Split(new []{','}, StringSplitOptions.RemoveEmptyEntries);
                var usersRoles = _roleProviderApplicationService.GetRolesForUser(updatedUser.UserName);

                var rolesToRemove = usersRoles.Except(updatedRoles);
                foreach (var roleToRemove in rolesToRemove)
                {
                    _roleProviderApplicationService.DeleteUserFromRole(updatedUser.UserName, roleToRemove);
                }

                var rolesToAdd = updatedRoles.Except(usersRoles);
                foreach (var roleToAdd in rolesToAdd)
                {
                    _roleProviderApplicationService.AddUserToRole(updatedUser.UserName, roleToAdd);
                }
 
                return RedirectToAction("Index");
            }
            catch
            {
                return RedirectToAction("EditUser", new {id = updatedUser.Id});
            }
        }
        /// <summary>
        /// Adds a new membership user to the data source. 
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <param name="email"></param>
        /// <param name="passwordQuestion"></param>
        /// <param name="passwordAnswer"></param>
        /// <param name="isApproved"></param>
        /// <param name="providerUserKey"></param>
        /// <param name="status"></param>
        /// <returns></returns>
        public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status)
        {             
            //TODO: All code shall be moved into the application service.
            User newUser = new User();

            newUser.UserName = username;
            newUser.Password = password;
            newUser.Email = email;
            newUser.CreationDate = DateTime.Now;
            newUser.LastActivity = DateTime.Now;
            newUser.LastLockedOutDate = DateTime.Now;
            newUser.LastLoginDate = DateTime.Now;
            newUser.LastPasswordChangedDate = DateTime.Now;
                

            if (_membershipProviderApplicationService.GetUser(newUser.UserName, false, ProviderName) != null)
            {
                status = MembershipCreateStatus.DuplicateUserName;
            }
            else if (_membershipProviderApplicationService.GetUserByMail(newUser.Email, ProviderName) != null)
            {
                status = MembershipCreateStatus.DuplicateEmail;
            }
            else
            {
                try
                {
                    _membershipProviderApplicationService.CreateUser(newUser);
                    status = MembershipCreateStatus.Success;
                    return newUser.ToMembershipUser();
                }
                catch(Exception e)
                {
                    status = MembershipCreateStatus.UserRejected;
                    throw new Exception(e.Message,e);
                }
            }
                      

            return null;
        }
 public void AddAdviceRequest(User user, AdviceBase advice, string userAgent, string imei, string model, string osVersion)
 {
     throw new NotImplementedException();
 }