Пример #1
0
        public bool EditFavourite(string recipeId, int userId, string description)
        {
            if (string.IsNullOrWhiteSpace(recipeId))
            {
                MessageBox.Show("Please choose recipe");
                return(false);
            }
            _repo = GetJsRepository();
            var favourite = _repo.Favourites.FirstOrDefault(f => f.RecipeId == recipeId && f.UserId == userId);

            if (favourite != null)
            {
                favourite.Description = description;
                _repo.Save();
                favourite             = AuthorizedUser.Favourites.FirstOrDefault(f => f.RecipeId == recipeId && f.UserId == userId);
                favourite.Description = description;
                favourite             = context.Favourites.FirstOrDefault(f => f.RecipeId == recipeId && f.UserId == userId);
                favourite.Description = description;
                context.SaveChanges();
                return(true);
            }
            else
            {
                MessageBox.Show("There is not favourites like it. Check the currency of the inpuy data");
                return(false);
            }
        }
Пример #2
0
        public bool RegisterUser(string name, string lastname, string email, string password)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                MessageBox.Show("User name cannot be empty");
                return(false);
            }
            if (string.IsNullOrWhiteSpace(lastname))
            {
                MessageBox.Show("User lastname cannot be empty");
                return(false);
            }
            if (string.IsNullOrWhiteSpace(email))
            {
                MessageBox.Show("User email cannot be empty");
                return(false);
            }
            if (string.IsNullOrWhiteSpace(PasswordHelpers.GetHash(password)))
            {
                MessageBox.Show("User password cannot be empty");
                return(false);
            }


            if (context.Users.FirstOrDefault(u => u.Email == email) == null)
            {
                var user = new User()
                {
                    Name       = name,
                    LastName   = lastname,
                    Email      = email,
                    Password   = PasswordHelpers.GetHash(password),
                    Favourites = new List <Favourite>()
                };
                Users.Add(user);
                context.Users.Add(user);
                context.SaveChanges();
                _repo = GetJsRepository();
                _repo.Users.Add(user);
                _repo.Save();
                return(true);
            }
            else
            {
                return(false);
            }
        }
Пример #3
0
        public bool AddFavourite(string recipeId, int userId, string description)
        {
            if (string.IsNullOrWhiteSpace(recipeId))
            {
                MessageBox.Show("Please choose recipe");
                return(false);
            }
            var fav = new Favourite {
                RecipeId = recipeId, UserId = userId, Description = description
            };

            AuthorizedUser.Favourites.Add(fav);
            context.Favourites.Add(fav);
            context.SaveChanges();
            _repo = GetJsRepository();
            _repo.Favourites.Add(fav);
            _repo.Save();
            return(true);
        }
Пример #4
0
        public Checker()
        {
            _repo = GetJsRepository();
            var user = new User()
            {
                Name       = "name4",
                Email      = "email",
                Password   = "******",
                Favourites = new List <Favourite>()
            };
            var fav = new Favourite()
            {
                Description = "dsf2",
                RecipeId    = "2",
                Id          = 2
            };

            // _repo.favouritesdata.ToList().Add(fav);
            _repo.Save();
            //_repo.SaveUser(users);
        }