Example #1
0
        public Publisher GetPublisherByCountryAndStatus(string countryCode, PublisherStatus status, Direction direction, int publisherId)
        {
            Publisher result = new Publisher();

            using (MailPusherDBContext context = new MailPusherDBContext())
            {
                var query = context.Publishers.Include(x => x.NACE);
                if (direction == Direction.Next)
                {
                    query = query.Where(x => x.ID > publisherId);
                }

                if (direction == Direction.Previous)
                {
                    query = query.Where(x => x.ID < publisherId);
                }

                if (!string.IsNullOrEmpty(countryCode))
                {
                    query = query.Where(x => x.Language == countryCode);
                }

                result = query.FirstOrDefault(x => x.Status == status);
            }
            return(result);
        }
Example #2
0
        public ActionResult GetPrevPublisher(string countryCode, int publisherId, PublisherStatus status)
        {
            PublisherHelper helper    = new PublisherHelper();
            Publisher       publisher = helper.GetPublisherByCountryAndStatus(countryCode, status, Direction.Previous, publisherId);

            return(Json(GetPublisherEmail(publisher), JsonRequestBehavior.AllowGet));
        }
Example #3
0
        public ActionResult ChangePublisherStatus(PublisherStatus status, int id)
        {
            string          currentUserId = User.Identity.GetUserId();
            PublisherHelper helper        = new PublisherHelper();

            return(Json(helper.ChangePublisherStatus(status, id, currentUserId)));
        }
Example #4
0
        public Email GetEmailByPublisherCountryAndStatus(string countryCode, PublisherStatus status)
        {
            Email result = new Email();

            using (var context = new MailPusherDBContext())
            {
                result = GenerateQueryForEmailByPublisherCountryAndStatus(context, countryCode, status, null, 0).FirstOrDefault();
            }
            return(result);
        }
Example #5
0
        public Email GetPrevEmailByPublisherCountryAndStatus(string countryCode, PublisherStatus status, int publisherId)
        {
            Email result = new Email();

            using (var context = new MailPusherDBContext())
            {
                result = GenerateQueryForEmailByPublisherCountryAndStatus(context, countryCode, status, publisherId, Direction.Previous).FirstOrDefault();
            }
            return(result);
        }
Example #6
0
        public Email GetFirstPublisherEmail(PublisherStatus status, int publisherID)
        {
            Email result = new Email();

            using (var context = new MailPusherDBContext())
            {
                result = context.Emails.OrderBy(x => x.ID).FirstOrDefault(x => x.PublisherID == publisherID);
            }
            return(result);
        }
Example #7
0
        public static string GetFormtedStatus(PublisherStatus status, DateTime?changed)
        {
            string datePart = string.Empty;

            if (changed.HasValue)
            {
                datePart = string.Format("({0:yyyy-MM-dd})", changed.Value.ToUniversalTime());
            }
            return(string.Format("{0} {1}", status.ToString(), datePart));
        }
Example #8
0
        public Publisher GetFirstPublisherByStatus(PublisherStatus status)
        {
            Publisher result = new Publisher();

            using (MailPusherDBContext context = new MailPusherDBContext())
            {
                result = context.Publishers.Include(x => x.NACE).FirstOrDefault(x => x.Status == status);
            }
            return(result);
        }
Example #9
0
        public int GetTotalFilteredRecords(string searchCriteria, PublisherStatus publisherStatuses, bool isPotentiallyCancelled, List <string> countries, List <int> categories, int minEmailAmount)
        {
            int result = 0;

            using (MailPusherDBContext context = new MailPusherDBContext())
            {
                result = AddFilters(context, searchCriteria, publisherStatuses, isPotentiallyCancelled, countries, categories, minEmailAmount).Count();
            }
            return(result);
        }
Example #10
0
        public ActionResult GetFirstPublisherEmail(string countryCode, PublisherStatus status)
        {
            //TODO move this to user settings, don't make during search!!
            UserSettingsHelper usHelper = new UserSettingsHelper();

            usHelper.Update(User.Identity.GetUserId(), countryCode);
            //TODO move this to user settings, don't make during search!!
            EmailHelper helper = new EmailHelper();

            return(Json(helper.GetEmailByPublisherCountryAndStatus(countryCode, status), JsonRequestBehavior.AllowGet));
        }
Example #11
0
        public ActionResult Get(IDataTablesRequest request, PublisherStatus publisherStatuses, bool isPotentiallyCancelled, List <string> countries, List <int> categories, int minEmailAmount)
        {
            PublisherHelper helper = new PublisherHelper();

            var filteredData = helper.GetPublishersWithStats(request.Start, request.Length, request.Search.Value, publisherStatuses, isPotentiallyCancelled, countries, categories, minEmailAmount);

            var response = DataTablesResponse.Create(request, helper.GetTotalRecords(),
                                                     helper.GetTotalFilteredRecords(request.Search.Value, publisherStatuses, isPotentiallyCancelled, countries, categories, minEmailAmount),
                                                     filteredData);

            // Easier way is to return a new 'DataTablesJsonResult', which will automatically convert your
            // response to a json-compatible content, so DataTables can read it when received.
            return(new DataTablesJsonResult(response, JsonRequestBehavior.AllowGet));
        }
Example #12
0
        public Email GetFirstPublisherEmail(PublisherStatus status)
        {
            Email result = new Email();

            using (var context = new MailPusherDBContext())
            {
                var publisher = context.Publishers.FirstOrDefault(x => x.Status == status);
                if (publisher != null)
                {
                    result = context.Emails.OrderBy(x => x.ID).FirstOrDefault(x => x.PublisherID == publisher.ID);
                }
            }
            return(result);
        }
Example #13
0
        public Publisher GetFirstPublisherByCountryAndStatus(string countryCode, PublisherStatus status)
        {
            Publisher result = new Publisher();

            using (MailPusherDBContext context = new MailPusherDBContext())
            {
                var query = context.Publishers.Include(x => x.NACE);
                if (!string.IsNullOrEmpty(countryCode))
                {
                    query = query.Where(x => x.Language == countryCode);
                }
                result = query.FirstOrDefault(x => x.Status == status);
            }
            return(result);
        }
Example #14
0
 public bool ChangePublisherStatus(PublisherStatus status, int id, string userId)
 {
     using (MailPusherDBContext context = new MailPusherDBContext())
     {
         Publisher result = context.Publishers.FirstOrDefault(x => x.ID == id);
         if (status != result.Status)
         {
             result.StatusChanged = DateTime.UtcNow;
         }
         result.Status               = status;
         result.UpdaterId            = userId;
         result.Updated              = DateTime.UtcNow;
         context.Entry(result).State = EntityState.Modified;
         context.SaveChanges();
     }
     return(true);
 }
Example #15
0
        public Email GetPrevEmailByPublisherCountryAndStatus(string countryCode, PublisherStatus status, int publisherId)
        {
            EmailRepo repo = new EmailRepo();

            return(Map(repo.GetPrevEmailByPublisherCountryAndStatus(countryCode, status, publisherId), countryCode));
        }
Example #16
0
        public Email GetEmailByPublisherCountryAndStatus(string countryCode, PublisherStatus status)
        {
            EmailRepo repo = new EmailRepo();

            return(Map(repo.GetEmailByPublisherCountryAndStatus(countryCode, status), countryCode));;
        }
Example #17
0
        public List <Publisher> GetPublishers(int start, int length, string searchCriteria, PublisherStatus publisherStatuses, bool isPotentiallyCancelled)
        {
            PublisherRepo repo = new PublisherRepo();

            return(Map(repo.GetPuglishers(start, length, searchCriteria, publisherStatuses, isPotentiallyCancelled, null, null, 0)));
        }
Example #18
0
        public List <Publisher> GetPublishersWithStats(int start, int length, string searchCriteria, PublisherStatus publisherStatuses, bool isPotentiallyCancelled, List <string> countries, List <int> categories, int minEmailAmount)
        {
            PublisherRepo    repo       = new PublisherRepo();
            List <Publisher> publishers = Map(repo.GetPuglishers(start, length, searchCriteria, publisherStatuses, isPotentiallyCancelled, countries, categories, minEmailAmount));
            var publishersStats         = repo.GetStats(publishers.Select(x => x.ID).ToList());

            foreach (var publisher in publishers)
            {
                var currentPublisherStats = publishersStats.FirstOrDefault(x => x.PublisherId == publisher.ID);
                publisher.ReceivedEmails = currentPublisherStats == null ? 0 : currentPublisherStats.ReceivedEmails;
            }
            return(publishers);
        }
Example #19
0
        public Publisher GetFirstPublisherByStatus(PublisherStatus publisherStatus)
        {
            PublisherRepo repo = new PublisherRepo();

            return(Map(repo.GetFirstPublisherByStatus(publisherStatus)));
        }
Example #20
0
        private IQueryable <Email> GenerateQueryForEmailByPublisherCountryAndStatus(MailPusherDBContext context, string countryCode, PublisherStatus status, int?publisherId, Direction direction)
        {
            var query = context.Publishers.Where(x => x.Status == status);

            if (!string.IsNullOrEmpty(countryCode))
            {
                query = query.Where(x => x.Language == countryCode);
            }
            if (publisherId.HasValue)
            {
                if (direction == Direction.Next)
                {
                    query = query.Where(x => x.ID > publisherId.Value);
                }
                if (direction == Direction.Previous)
                {
                    query = query.Where(x => x.ID < publisherId.Value);
                }
            }
            return(query.Join(context.Emails, pub => pub.ID, em => em.PublisherID, (pub, em) => em));
        }
Example #21
0
        public ActionResult GetPrevPublisherEmail(string countryCode, PublisherStatus status, int publisherId)
        {
            EmailHelper helper = new EmailHelper();

            return(Json(helper.GetPrevEmailByPublisherCountryAndStatus(countryCode, status, publisherId), JsonRequestBehavior.AllowGet));
        }
Example #22
0
        public List <Publisher> GetPuglishers(int start, int length, string searchCriteria, PublisherStatus publisherStatuses, bool isPotentiallyCancelled, List <string> countries, List <int> categories, int minEmailAmount)
        {
            List <Publisher> result = new List <Publisher>();

            using (MailPusherDBContext context = new MailPusherDBContext())
            {
                var query = AddFilters(context, searchCriteria, publisherStatuses, isPotentiallyCancelled, countries, categories, minEmailAmount);

                var tmpResult = query.Include(x => x.NACE).OrderBy(x => x.ID).Skip(start).Take(length);
                result = tmpResult.ToList();
            }
            return(result);
        }
Example #23
0
        protected IQueryable <Publisher> AddFilters(MailPusherDBContext context, string searchCriteria, PublisherStatus publisherStatuses, bool isPotentiallyCancelled, List <string> countries, List <int> categories, int minEmailAmount)
        {
            var query = context.Publishers.Select(x => x);

            if (publisherStatuses != 0)
            {
                query = query.Where(x => (x.Status & publisherStatuses) > 0);
            }
            if (!string.IsNullOrEmpty(searchCriteria))
            {
                query = query.Where(x => x.Name.Contains(searchCriteria));
            }
            if (isPotentiallyCancelled)
            {
                var date = DateTime.UtcNow.AddDays(-30);
                query = query.Where(x => x.LastReceivedEmail < date);
            }
            if (countries != null && countries.Count > 0)
            {
                query = query.Where(x => countries.Contains(x.Language));
            }
            if (categories != null && categories.Count > 0)
            {
                query = query.Where(x => categories.Contains(x.NACEID));
            }
            if (minEmailAmount > 0)
            {
                query = query.Where(x => context.Emails.Where(y => y.PublisherID == x.ID).Count() >= minEmailAmount);
            }
            return(query);
        }
Example #24
0
        public int GetTotalFilteredRecords(string searchCriteria, PublisherStatus statuses, bool isPotentiallyCancelled, List <string> countries, List <int> categories, int minEmailAmount)
        {
            PublisherRepo repo = new PublisherRepo();

            return(repo.GetTotalFilteredRecords(searchCriteria, statuses, isPotentiallyCancelled, countries, categories, minEmailAmount));
        }
Example #25
0
        public Publisher GetPublisherByCountryAndStatus(string countryCode, PublisherStatus status, Direction direction, int publisherId)
        {
            PublisherRepo repo = new PublisherRepo();

            return(Map(repo.GetPublisherByCountryAndStatus(countryCode, status, direction, publisherId), countryCode));
        }
Example #26
0
        public Email GetFirstPublisherEmail(PublisherStatus status, int publisherId)
        {
            EmailRepo repo = new EmailRepo();

            return(Map(repo.GetFirstPublisherEmail(status, publisherId)));
        }
Example #27
0
        public bool ChangePublisherStatus(PublisherStatus status, int id, string userId)
        {
            PublisherRepo repo = new PublisherRepo();

            return(repo.ChangePublisherStatus(status, id, userId));
        }
Example #28
0
        public Publisher GetFirstPublisherByCountryAndStatus(string countryCode, PublisherStatus publisherStatus)
        {
            PublisherRepo repo = new PublisherRepo();

            return(Map(repo.GetFirstPublisherByCountryAndStatus(countryCode, publisherStatus), countryCode));;
        }