Ejemplo n.º 1
0
        public async Task <Recipe> Add(Recipe recipe)
        {
            var newRecipe = new Recipe
            {
                Image       = recipe.Image,
                Servings    = recipe.Servings,
                Time        = recipe.Time,
                Title       = recipe.Title,
                Description = recipe.Description,
                FkUser      = recipe.FkUser
            };
            await _dataContext.AddAsync(newRecipe);

            await _dataContext.SaveChangesAsync();


            foreach (var item in recipe.Products)
            {
                var product = new Product
                {
                    Name     = item.Name,
                    Quantity = item.Quantity,
                    FkRecipe = newRecipe.Id
                };
                await _dataContext.Product.AddAsync(product);
            }
            await _dataContext.SaveChangesAsync();

            return(newRecipe);
        }
Ejemplo n.º 2
0
        public async Task <Comment> Add(Comment comment)
        {
            await _dataContext.AddAsync(comment);

            await _dataContext.SaveChangesAsync();

            return(comment);
        }
Ejemplo n.º 3
0
        public async Task <Event> Add(Event ev)
        {
            await _dataContext.AddAsync(ev);

            await _dataContext.SaveChangesAsync();

            return(ev);
        }
Ejemplo n.º 4
0
        public async Task <bool> Delete(int id)
        {
            var value = await _dataContext.User.Where(x => x.Id == id).FirstOrDefaultAsync();

            if (value == null)
            {
                return(false);
            }
            var values = _dataContext.User.Remove(value);
            await _dataContext.SaveChangesAsync();

            return(true);
        }
Ejemplo n.º 5
0
        public async Task <bool> Update(int id, NewProductDto[] newProducts)
        {
            var findProducts = await _dataContext.Product.Where(x => x.FkRecipe.Equals(id)).ToListAsync();

            if (findProducts.Count == 0 || findProducts == null)
            {
                throw new ArgumentNullException();
            }

            foreach (var item in findProducts)
            {
                var findProduct = await _dataContext.Product.FirstOrDefaultAsync(x => x.Id.Equals(item.Id));

                foreach (var a in newProducts)
                {
                    findProduct.Name     = a.Name;
                    findProduct.Quantity = a.Quantity;
                }


                _dataContext.Update(findProduct);
            }

            await _dataContext.SaveChangesAsync();

            return(true);
        }
Ejemplo n.º 6
0
        public async Task <User> Register(User user, string password)
        {
            CreatePasswordHash(password, out var passwordHash, out var passwordSalt);

            user.PasswordHash = passwordHash;
            user.PasswordSalt = passwordSalt;
            user.Token        = CreateToken(user);

            await _context.User.AddAsync(user);

            await _context.SaveChangesAsync();

            return(user);
        }