Пример #1
0
 public IEnumerable <UserFriendDto> AddUserFriendById(int _userFollowerId, int _userFollowedId)
 {
     _context.Add(new UserFriend {
         UserFollowerId = _userFollowerId, UserFollowedId = _userFollowedId
     });
     _context.Add(new UserFriend {
         UserFollowerId = _userFollowedId, UserFollowedId = _userFollowerId
     });
     _context.SaveChanges();
     return(_context.UserFriends.Select(x => x.AsDto()));
 }
Пример #2
0
        public IEnumerable <RecipeDto> CreateRecipe(RecipeInputDto r)
        {
            var toAdd = new Recipe
            {
                CreatorId   = r.creatorId,
                Name        = r.name,
                Description = r.description,
                Rating      = (decimal)r.rating,
                Tag         = r.tag,
            };

            _context.Add(toAdd);
            _context.SaveChanges();
            foreach (var ingredient in r.Ingredients)
            {
                int?ingredientID = _context.Ingredients.Where(i => i.Name == ingredient.name).Select(x => x.Id).FirstOrDefault();
                if (ingredientID != 0)
                {
                    //link to recipe
                    var RecipeIngredient = new RecipeIngredient();
                    RecipeIngredient.IngredientId = ingredientID;
                    RecipeIngredient.RecipeId     = toAdd.Id;
                    _context.RecipeIngredients.Add(RecipeIngredient);
                    _context.SaveChanges();
                }
            }

            return(_context.Recipes.Select(x => x.AsDto()).ToList());
        }
Пример #3
0
 public IEnumerable <UserDto> CreateUser(UserInputDto u)
 {
     _context.Add(new User
     {
         //Id = u.id,
         Name     = u.name,
         Surname  = u.surname,
         Email    = u.email,
         Verified = u.verified,
         Admin    = u.admin
     });
     _context.SaveChanges();
     return(_context.Users.Select(u => u.AsDto()));
 }