Пример #1
0
        // GET: OfferCode
        public ActionResult List(int offerId)
        {
            OfferCodeListViewModel model = new OfferCodeListViewModel();

            model.OfferId       = offerId;
            model.OfferCodeList = new List <OfferCodeViewModel>();
            OfferService offerService = new OfferService();
            Offer        offer        = offerService.GetOffer(offerId);

            if (offer == null || !offerIsOwnedByUserCompany(offerId))
            {
                model.ErrorMessage = "Offer not found.";
                return(View(model));
            }
            model.OfferTitle = offer.Title;

            //Pull data from database and display in table.
            var offerCodeList = offerService.GetAllOfferCodes(offer.Id);
            var offerList     = offerService.GetAllOfferCodes(offer.Id);

            foreach (var item in offerCodeList)
            {
                OfferCodeViewModel offerCodeViewModel = new OfferCodeViewModel();
                offerCodeViewModel.Code        = item.Code;
                offerCodeViewModel.OfferId     = item.OfferId;
                offerCodeViewModel.Id          = item.Id;
                offerCodeViewModel.BuyerEmail  = item.BuyerEmail;
                offerCodeViewModel.DateClaimed = item.ClaimedOn;
                model.OfferCodeList.Add(offerCodeViewModel);
            }
            return(View(model));
        }
Пример #2
0
        public bool isCodeAvailable(int offerId)
        {
            var   offerService = new OfferService();
            Offer offer        = offerService.GetOffer(offerId);
            //List<OfferCode> offerCodeList = new List<OfferCode>();
            var offerCodeList = offerService.GetAllOfferCodes(offer.Id);

            return(offerCodeList.Any(oc => String.IsNullOrEmpty(oc.ClaimingUser)));
            //foreach (OfferCode item in offerCodeList)
            //{
            //    offerCodeList.Add(item);
            //    if (item.ClaimingUser == null)
            //    {
            //        nullCount++;
            //    }
            //}
            //if (nullCount > 0)
            //{
            //    return true;
            //}
            //else
            //{
            //    return false;
            //}
        }
Пример #3
0
        public string GetOfferCodeString(int offerId)
        {
            var offerService  = new OfferService();
            var offer         = offerService.GetOffer(offerId);
            var offerCodeList = offerService.GetAllOfferCodes(offerId);
            //offerCodeList = offerCodeList.Where(oc => oc.ClaimedOn != null).ToList();
            string offerCodeString = "Offer Title,Category,Code,Buyer,Date\n";

            foreach (var item in offerCodeList)
            {
                //from https://stackoverflow.com/questions/29893631/how-to-add-double-quotes-to-a-string-which-contains-comma
                //text = text.Contains(",") ? String.Format("\"{0}\"", text) : text;



                offerCodeString +=
                    (offer.Title.Contains(",") ? String.Format("\"{0}\"", offer.Title) : offer.Title)
                    + ",";
                offerCodeString +=
                    (offer.Category.Contains(",") ? String.Format("\"{0}\"", offer.Category) : offer.Category)
                    + ",";
                offerCodeString +=
                    (item.Code.Contains(",") ? String.Format("\"{0}\"", item.Code) : item.Code)
                    + ",";
                offerCodeString +=
                    (item.BuyerEmail.Contains(",") ? String.Format("\"{0}\"", item.BuyerEmail) : item.BuyerEmail)
                    + ",";
                offerCodeString +=
                    (item.ClaimedOn.Contains(",") ? String.Format("\"{0}\"", item.ClaimedOn) : item.ClaimedOn)
                    + ",";
                offerCodeString += "\n";    //new row
            }
            return(offerCodeString);
        }
Пример #4
0
        public string CodeForUser(int offerId, string userId)
        {
            var   offerService = new OfferService();
            Offer offer        = offerService.GetOffer(offerId);

            var offerCodeList = offerService.GetAllOfferCodes(offer.Id);
            var offerCode     = offerCodeList.Where(oc => oc.ClaimingUser == userId).FirstOrDefault();

            if (offerCode != null)
            {
                return(offerCode.Code);
            }
            else
            {
                return(null);
            }
        }