Exemplo n.º 1
0
        public OfferBulletinViewModel CreateOfferPrompt(int referenceA, int referenceB)
        {
            bool check = isOffered(referenceA, referenceB);

            if (!check)
            {
                Item    receiverItem    = db.Item.Where(i => i.ItemId == referenceA).FirstOrDefault();
                Account receiverAccount = db.Account.Where(ra => ra.AccountId == receiverItem.AccountId).FirstOrDefault();
                Item    senderItem      = db.Item.Where(i => i.ItemId == referenceB).FirstOrDefault();
                Account senderAccount   = db.Account.Where(ra => ra.AccountId == senderItem.AccountId).FirstOrDefault();
                if (receiverItem != null && senderItem != null)
                {
                    OfferBulletinViewModel offerMake = new OfferBulletinViewModel();
                    offerMake.Confirmed    = 0;
                    offerMake.ItemIdA      = receiverItem.ItemId;
                    offerMake.NameA        = receiverItem.Name;
                    offerMake.CaptionA     = receiverItem.Caption;
                    offerMake.DescriptionA = receiverItem.Description;
                    offerMake.UserA        = receiverAccount.Username;
                    offerMake.ItemIdB      = senderItem.ItemId;
                    offerMake.NameB        = senderItem.Name;
                    offerMake.CaptionB     = senderItem.Caption;
                    offerMake.DescriptionB = senderItem.Description;
                    offerMake.UserB        = senderAccount.Username;
                    return(offerMake);
                }
            }
            return(null);
        }
Exemplo n.º 2
0
        public ActionResult MakeOfferConfirm(int referenceA, int referenceB)
        {
            if (referenceA == 0 || referenceB == 0)
            {
                return(RedirectToAction("Index", "Trades")); //Need to insert proper error message
            }
            OfferBulletinViewModel makeOfferConfirm = tradeManager.CreateOfferPrompt(referenceA, referenceB);

            if (makeOfferConfirm == null)
            {
                return(RedirectToAction("Index", "Trades"));
            }
            return(View(makeOfferConfirm));
        }
Exemplo n.º 3
0
        public IEnumerable <OfferBulletinViewModel> OfferList(OfferType type, int reference = -1)
        {
            string emailAddress = HttpContext.Current.User.Identity.Name.ToString();

            if (!global.IsUniqueEmailAddress(emailAddress))
            {
                Account userAccount = global.GetAccount(emailAddress);
                List <OfferBulletinViewModel> offerList = new List <OfferBulletinViewModel>();
                dynamic offerResults = null;
                switch (type)
                {
                case OfferType.Receiver:
                    offerResults = (reference == -1) ?
                                   db.Offer.Join(db.OfferDetail, o => o.OfferId, od => od.OfferId, (o, od) => new { o, od })
                                   .OrderByDescending(ord => ord.od.UploadDate)
                                   .Where(ofr => ofr.o.ReceiverId == userAccount.AccountId).ToList() :
                                   db.Offer.Join(db.OfferDetail, o => o.OfferId, od => od.OfferId, (o, od) => new { o, od })
                                   .OrderByDescending(ord => ord.o.ReceiverItemId == reference).ThenBy(ord => ord.od.UploadDate)
                                   .Where(ofr => ofr.o.ReceiverId == userAccount.AccountId).ToList();
                    break;

                case OfferType.Sender:
                    offerResults = db.Offer.Join(db.OfferDetail, o => o.OfferId, od => od.OfferId, (o, od) => new { o, od })
                                   .OrderByDescending(ord => ord.od.UploadDate)
                                   .Where(ofr => ofr.o.AccountId == userAccount.AccountId).ToList();
                    break;
                }
                if (offerResults != null)
                {
                    if (offerResults.Count > 0)
                    {
                        foreach (var offer in offerResults)
                        {
                            int     recId           = offer.o.ReceiverItemId;
                            int     senId           = offer.o.SenderItemId;
                            Item    receiverItem    = db.Item.Where(i => i.ItemId == recId).FirstOrDefault();
                            Account receiverAccount = db.Account.Where(ra => ra.AccountId == receiverItem.AccountId).FirstOrDefault();
                            Item    senderItem      = db.Item.Where(i => i.ItemId == senId).FirstOrDefault();
                            Account senderAccount   = db.Account.Where(ra => ra.AccountId == senderItem.AccountId).FirstOrDefault();
                            if (receiverItem != null && senderItem != null)
                            {
                                OfferBulletinViewModel offerMake = new OfferBulletinViewModel();
                                offerMake.Confirmed    = offer.od.Confirmed;
                                offerMake.ItemIdA      = receiverItem.ItemId;
                                offerMake.NameA        = receiverItem.Name;
                                offerMake.CaptionA     = receiverItem.Caption;
                                offerMake.DescriptionA = receiverItem.Description;
                                offerMake.UserA        = receiverAccount.Username;
                                Image imageA = imaging.ServeImage(receiverItem.ItemId);
                                if (imageA != null)
                                {
                                    offerMake.ImageStringA = imageA.ImageSource;
                                }
                                offerMake.ItemIdB      = senderItem.ItemId;
                                offerMake.NameB        = senderItem.Name;
                                offerMake.CaptionB     = senderItem.Caption;
                                offerMake.DescriptionB = senderItem.Description;
                                offerMake.UserB        = senderAccount.Username;
                                Image imageB = imaging.ServeImage(senderItem.ItemId);
                                if (imageB != null)
                                {
                                    offerMake.ImageStringB = imageB.ImageSource;
                                }
                                offerList.Add(offerMake);
                            }
                        }
                    }
                    return(offerList);
                }
            }
            return(null);
        }