Пример #1
0
        public async Task <IdentityResult> CreateAsync(User user, CancellationToken cancellationToken)
        {
            _db.User.Add(user);
            await _db.SaveChangesAsync(cancellationToken);

            return(IdentityResult.Success);
        }
Пример #2
0
        public async Task SetFavorite(int roomId, int status)
        {
            int userId = Convert.ToInt16(_userManager.GetUserId(HttpContext.User));
            var FavCnt = await _context.Favorites.Where(t => t.RoomId == roomId && t.UserId == userId).CountAsync();

            if (FavCnt == 0)
            {
                var entry = new Favorites
                {
                    Status = status,
                    RoomId = roomId,
                    UserId = userId
                };
                await _context.Favorites.AddAsync(entry);
            }
            else
            {
                var Fav = await _context.Favorites.SingleAsync(t => t.RoomId == roomId && t.UserId == userId);

                Fav.Status = status;
                _context.Favorites.Update(Fav);
            }
            await _context.SaveChangesAsync();
        }