Пример #1
0
        public bool AddUserToWatchlist(string email, string username)
        {
            var user = GetUser(email);

            if (user.Watchlist.Any(x => x.Name.CompareIgnoreCase(username))) return false;

            var watchItem = new WatchDto(username);
            user.Watchlist.Add(watchItem);
            return SetUser(user);
        }
Пример #2
0
        public IHttpActionResult CreateWatch(WatchDto watchDto)
        {
            var viewer = context.Viewers
                         .SingleOrDefault(v => v.Id == watchDto.ViewerId);

            if (viewer == null)
            {
                return(BadRequest("Viewer is not Valid"));
            }

            var series = context.Series
                         .Where(s => watchDto.SerieIds.Contains(s.Id)).ToList();

            if (series.Count != watchDto.SerieIds.Count)             //το api στέλνει 5 ids στη βάση βρίσκω 3
            {
                return(BadRequest("One or More Series is Invalid")); //(ex. κάποιος σβήνει Τη σειρά)
            }
            foreach (var serie in series)
            {
                if (!serie.IsAvailable)
                {
                    return(BadRequest("Serie is not Available"));
                }

                var watch = new Watch()
                {
                    Viewer      = viewer,
                    Serie       = serie,
                    DateStarted = DateTime.Now
                };

                context.Watches.Add(watch);
            }
            context.SaveChanges();

            return(Ok());
        }