示例#1
0
        public void AddCity(CityDTO dto)
        {
            var city = new City
            {
                Name     = dto.Name,
                Distance = dto.Distance
            };

            _db.Add(city);
            _db.SaveChanges();
        }
示例#2
0
        public void AddAirplane(AirplaneDTO dto)
        {
            var airplane = new Airplane
            {
                Distance          = dto.Distance,
                Model             = dto.Model,
                LiftingCapacity   = dto.LiftingCapacity,
                PassengerCapacity = dto.PassengerCapacity
            };

            _db.Add(airplane);
            _db.SaveChanges();
        }
示例#3
0
        public async Task <UserDTO> PostAsync(UserDTO entity)
        {
            if (string.IsNullOrEmpty(entity.Password) || string.IsNullOrEmpty(entity.Login))
            {
                throw new ArgumentException("Login and password are required");
            }
            var user = mapper.Map <UserDTO, User>(entity);

            byte[] passwordHash, passwordSalt;
            CreatePasswordHash(entity.Password, passwordHash: out passwordHash, passwordSalt: out passwordSalt);
            user.PasswordHash = passwordHash;
            user.PasswordSalt = passwordSalt;
            user.Role         = Role.User;
            context.Add(user);
            await context.SaveChangesAsync();

            return(mapper.Map <User, UserDTO>(user));
        }