コード例 #1
0
        public async Task <DonkeySellUser> CreateOrUpdateUser(ViewUser viewUser)
        {
            if (!viewUser.IsValid())
            {
                throw new FormatException();
            }

            DonkeySellUser newUser = null;

            if (context.Users.Any(x => x.UserName == viewUser.UserName))
            {
                newUser = await UpdateUser(viewUser);
            }
            else
            {
                newUser = await CreateUser(viewUser);

                // mail confirmation
                if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings.Get("password")))
                {
                    await mailSender.SendEmailConfirmationMessage(newUser.Email, newUser.ConfirmationGuid, viewUser.UserName);
                }
            }

            return(newUser);
        }
コード例 #2
0
        private async Task <DonkeySellUser> CreateUser(ViewUser viewUser)
        {
            if (!Checks.PasswordIsValid(viewUser.Password))
            {
                throw new FormatException();
            }

            Guid           guid = Guid.NewGuid();
            DonkeySellUser user = new DonkeySellUser()
            {
                UserName         = viewUser.UserName,
                Email            = viewUser.Email,
                UserId           = guid.ToString(),
                Address          = viewUser.Address,
                Avatar           = viewUser.Avatar,
                Facebook         = viewUser.Facebook,
                Phone            = viewUser.Phone,
                Twitter          = viewUser.Twitter,
                ConfirmationGuid = Guid.NewGuid().ToString()
            };

            await userManager.CreateAsync(user, viewUser.Password);

            var newUser = context.Users.Single(x => x.UserName == viewUser.UserName);

            return(newUser);
        }
コード例 #3
0
        private Message CreateMessage(DonkeySellUser user, Product product)
        {
            Message message = new Message()
            {
                UserId = user.UserId, UserName = user.UserName, DateCreated = DateTime.Now, Value = "This is a comment", ProductId = product.Id
            };

            return(message);
        }
コード例 #4
0
        public void Initialize()
        {
            TestInitialiser.Initialise();
            crudOnAlerts = TestInitialiser.ninjectKernel.kernel.Get <ICrudOnAlerts>();
            crudOnUsers  = TestInitialiser.ninjectKernel.kernel.Get <ICrudOnUsers>();
            var viewUser = TestInitialiser.CreateUser();

            user = crudOnUsers.CreateOrUpdateUser(viewUser).Result;
            var viewAlert = new ViewAlert()
            {
                ProductName = productName, UserId = user.UserId
            };

            alert = Mapper.Map <Alert>(viewAlert);
        }
コード例 #5
0
        private Product CreateProduct(DonkeySellUser user)
        {
            var categoryId = context.Categories.Single(x => x.Name == "Other").Id;
            var cityId     = context.Cities.Single(x => x.Name == "Bacau").Id;

            Product product = new Product()
            {
                Title          = "One plus 3",
                CityId         = cityId,
                DatePublished  = DateTime.Today,
                Description    = "no description!",
                UserName       = user.UserName,
                CategoryId     = categoryId,
                Price          = 1900,
                TradesAccepted = true
            };

            return(product);
        }
コード例 #6
0
        private DonkeySellUser CreateDonkeySellUser(string username, string email, string password)
        {
            var roles = new List <string> {
                "Active", "Admin", "AccountManager", "User"
            };

            foreach (string role in roles)
            {
                if (!roleManager.RoleExists(role))
                {
                    roleManager.Create(new IdentityRole(role));
                }
            }

            Guid           guid = Guid.NewGuid();
            DonkeySellUser user = new DonkeySellUser()
            {
                UserName = username, Email = email, UserId = guid.ToString(), ConfirmationGuid = Guid.NewGuid().ToString()
            };

            userManager.Create(user, password);

            return(user);
        }