Ejemplo n.º 1
0
        public async Task <User> Register(User user)
        {
            var hashedPassword = BCrypt.Net.BCrypt.HashPassword(user.Password);

            user.Password = hashedPassword;
            await context.Users.AddAsync(user);

            var data = await context.SaveChangesAsync();

            return(user);
        }
Ejemplo n.º 2
0
        public async Task <bool> MarkAsFavorite(long book, long user)
        {
            try {
                var fav = await context.FavoriteBooks
                          .Where(f => f.UserId == user && f.BookId == book)
                          .SingleOrDefaultAsync();

                if (fav == null && user != 0 && book != 0)
                {
                    var favorite = new FavoriteBook(user, book);
                    await context.FavoriteBooks.AddAsync(favorite);
                }
                return((await context.SaveChangesAsync()) > 0);
            } catch (Exception e) {
                Console.WriteLine(e.Message);
                return(false);
            }
        }
Ejemplo n.º 3
0
        public async Task <bool> AddToFavorites(long userId, long courseId)
        {
            try
            {
                var fav = await Context.FavoriteCourses
                          .Where(f => f.UserId == userId && f.CourseId == courseId)
                          .SingleOrDefaultAsync();

                if (fav == null && userId != 0 && courseId != 0)
                {
                    var favorite = new FavoriteCourse(userId, courseId);
                    await Context.FavoriteCourses.AddAsync(favorite);
                }

                return((await Context.SaveChangesAsync()) > 0);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return(false);
            }
        }