Esempio n. 1
0
        public Issue GetComic(int id)
        {
            Issue result = null;

            using (TransactionScope scope = new TransactionScope())
            {
                MyNextComicEntities context = null;

                try
                {
                    context = new MyNextComicEntities();
                    context.Configuration.AutoDetectChangesEnabled = false;

                    var issue = context.Comics.Where(x => x.Id_Comic == id).ToList().FirstOrDefault();

                    var mapper = new MyNextComicMapper();

                    result = mapper.MapIssue(issue);
                }
                catch (DbEntityValidationException e)
                {
                }

                context.Dispose();
                scope.Complete();
            }

            return(result);
        }
Esempio n. 2
0
        public User GetUserData(string userName)
        {
            var result = new User();

            using (TransactionScope scope = new TransactionScope())
            {
                MyNextComicEntities context = null;
                try
                {
                    context = new MyNextComicEntities();
                    context.Configuration.AutoDetectChangesEnabled = false;

                    var storedUser = context.Users.Where(x => x.Username == userName).FirstOrDefault();
                    if (storedUser != null)
                    {
                        result.UserId   = storedUser.Id;
                        result.UserName = storedUser.Username;
                        result.Email    = storedUser.Email;
                        result.IsAdmin  = storedUser.IsAdmin ?? false;

                        var preferences = context.Preferences.Where(x => x.UserID == storedUser.Id).ToList();
                        var comicsIds   = preferences.Select(x => x.ItemID).ToList();
                        if (preferences.Count() > 0)
                        {
                            var ratedComics = context.Comics.Where(x => comicsIds.Any(y => x.Id_Comic == y)).ToList();
                            var mapper      = new MyNextComicMapper();
                            var issues      = new List <Issue>();
                            foreach (var comic in ratedComics)
                            {
                                var issue = mapper.MapIssue(comic);
                                issue.Rating = preferences.Where(x => x.ItemID == comic.Id_Comic).FirstOrDefault().Value;
                                issues.Add(issue);
                            }

                            result.ComicList = issues.AsEnumerable();
                        }
                    }
                    else
                    {
                        context.Dispose();
                    }
                }
                catch (DbEntityValidationException e)
                {
                }

                scope.Complete();
            }

            return(result);
        }
Esempio n. 3
0
        public List <Issue> GetComics(string searchString, int genre, List <int> ids)
        {
            var result = new List <Issue>();

            using (TransactionScope scope = new TransactionScope())
            {
                MyNextComicEntities context = null;

                try
                {
                    context = new MyNextComicEntities();
                    context.Configuration.AutoDetectChangesEnabled = false;
                    var comics = new List <Comics>();
                    if (!string.IsNullOrEmpty(searchString))
                    {
                        comics = context.Comics.Where(x => x.Name.ToLower().Contains(searchString.ToLower())).OrderBy(x => x.Id).ToList();
                    }
                    else if (ids.Count() > 0)
                    {
                        comics = context.Comics.Where(x => ids.Contains(x.Id_Comic)).ToList();
                    }
                    else
                    {
                        comics = context.Comics.OrderBy(x => x.Id).ToList();
                    }

                    if (genre != 0)
                    {
                        comics = comics.Where(x => x.Genre == genre).ToList();
                    }

                    var mapper = new MyNextComicMapper();

                    foreach (var comic in comics)
                    {
                        result.Add(mapper.MapIssue(comic));
                    }
                }
                catch (DbEntityValidationException e)
                {
                }

                context.Dispose();
                scope.Complete();
            }

            return(result);
        }
Esempio n. 4
0
        public List <Issue> GetTopComics()
        {
            var result = new List <Issue>();

            using (TransactionScope scope = new TransactionScope())
            {
                MyNextComicEntities context = null;

                try
                {
                    context = new MyNextComicEntities();
                    context.Configuration.AutoDetectChangesEnabled = false;

                    var comics = new List <Issue>();


                    var preSelection = context.Preferences.OrderBy(x => Guid.NewGuid()).Take(8).ToList();

                    var Ids        = preSelection.Select(x => x.ItemID).ToList();
                    var comicsData = context.Comics.Where(x => Ids.Any(y => x.Id_Comic == y)).ToList();

                    var mapper = new MyNextComicMapper();

                    foreach (var comic in preSelection)
                    {
                        var mappedComic = mapper.MapIssue(comicsData.Where(x => x.Id_Comic == comic.ItemID).FirstOrDefault());
                        mappedComic.Rating = Math.Round(comic.Value, 0, MidpointRounding.AwayFromZero);
                        comics.Add(mappedComic);
                    }

                    result = comics;
                }
                catch (DbEntityValidationException e)
                {
                }

                context.Dispose();
                scope.Complete();
            }

            return(result);
        }