Beispiel #1
0
        public async Task <PlantDto> CreatePlant(CreatePlantDto input)
        {
            var plant = _mapper.Map <CreatePlantDto, Plant>(input);
            await _context.Plants.AddAsync(plant);

            await _context.SaveChangesAsync();

            var slike = input.Slike.Select(s => new PlantImage
            {
                UPrirodi = false,
                Slika    = s.Slika,
                BiljkaId = plant.Id
            }).ToList();

            var slikeUPrirodi = input.SlikeUPrirodi.Select(s => new PlantImage
            {
                UPrirodi = true,
                Slika    = s.Slika,
                BiljkaId = plant.Id
            }).ToList();

            await _context.PlantImages.AddRangeAsync(slike);

            await _context.PlantImages.AddRangeAsync(slikeUPrirodi);

            await _context.SaveChangesAsync();

            return(_mapper.Map <Plant, PlantDto>(plant));
        }
Beispiel #2
0
        public async Task <UserDto> CreateUser(UserDto input)
        {
            var user = new User
            {
                Username = input.Username,
                Password = HashConverter.CreateMD5(input.Password)
            };

            await _context.Users.AddAsync(user);

            await _context.SaveChangesAsync();

            return(_mapper.Map <User, UserDto>(user));
        }