Exemplo n.º 1
0
        /// <summary>
        /// Add a new user, given their details
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public async Task <User> AddUserAsync(string userName, string password)
        {
            User user = await _context.Users.FirstOrDefaultAsync(u => u.UserName == userName);

            ThrowIfUserFound(user, userName);

            user = new User
            {
                UserName = userName,
                Password = _hasher.Value.HashPassword(userName, password)
            };

            await _context.Users.AddAsync(user);

            await _context.SaveChangesAsync();

            return(user);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Add a named manufacturer, if it doesn't already exist
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public async Task <Manufacturer> AddAsync(string name)
        {
            name = name.CleanString();
            Manufacturer manufacturer = await GetAsync(a => a.Name == name);

            if (manufacturer == null)
            {
                manufacturer = new Manufacturer {
                    Name = name
                };
                await _context.Manufacturers.AddAsync(manufacturer);

                await _context.SaveChangesAsync();
            }

            return(manufacturer);
        }
        /// <summary>
        /// Add a named location, if it doesn't already exist
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public async Task <Location> AddAsync(string name)
        {
            name = name.CleanString();
            Location location = await GetAsync(a => a.Name == name);

            if (location == null)
            {
                location = new Location {
                    Name = name
                };
                await _context.Locations.AddAsync(location);

                await _context.SaveChangesAsync();
            }

            return(location);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Add a named airline, if it doesn't already exist
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public async Task <Airline> AddAsync(string name)
        {
            name = name.CleanString();
            Airline airline = await GetAsync(a => a.Name == name);

            if (airline == null)
            {
                airline = new Airline {
                    Name = name
                };
                await _context.Airlines.AddAsync(airline);

                await _context.SaveChangesAsync();
            }

            return(airline);
        }