Example #1
0
        public static int AcceptOffer(ref Selling offer, Guid userId, out int historyId)
        {
            if (offer == null || offer.SellingId < 0 || userId == Guid.Empty || offer.SellerId == Guid.Empty)
              {
            throw new ArgumentNullException();
              }

              DataRow row;
              int res = SellingDataAdapter.AcceptOffer(offer.SellingId, userId, out historyId, out row);
              if (res == 1)
              {
            var user = UsersFacade.GetUser(offer.SellerId);
            if (user != null)
            {
              var msg = MessageFactory.CreateByTemplate(MessageTemplate.SellingAccepted
            , userId, null, new[] { offer.Title, user.UserName });
              MessageFacade.AddFromSystemUser(msg);
            }
              }

              if (row != null)
              {
            offer = offer.Load<Selling>(row);
              }

              return res;
        }
Example #2
0
 public static void AcceptOffer(out Selling o, ref MembershipUser seller, ref MembershipUser buyer, out int history)
 {
     SelectOffer(out o, ref seller, ref buyer);
       int res = SellingFacade.AcceptOffer(ref o, buyer.UserId(), out history);
       Assert.AreEqual(res, 1);
       Assert.Greater(history, 0);
       Assert.AreEqual(o.TransactionPhase, TransactionPhase.Accept);
       Trace.WriteLine(o.ToXmlString());
 }
Example #3
0
 public static void ConfirmOffer(out Selling o, ref MembershipUser seller, ref MembershipUser buyer)
 {
     int history;
       AcceptOffer(out o, ref seller, ref buyer, out history);
       int res = SellingFacade.ConfirmOffer(ref o, out history);
       Assert.AreEqual(res, 1);
       Assert.Greater(history, 0);
       Assert.AreEqual(o.TransactionPhase, TransactionPhase.Submit);
       Trace.WriteLine(o.ToXmlString());
 }
 public void TestCreateOfferToSeller()
 {
     var seller = UsersFacadeHelper.GetRandomUser(null);
       Selling s = new Selling();
       s.Price = new decimal(100);
       var note = "stuff";
       var t = TransferFactory.CreateOfferToSeller(s, seller.UserId(), note);
       Assert.AreEqual(s.Price, t.Amount);
       Assert.AreEqual(note, t.Note);
       Assert.AreEqual(TransferStatus.Completed, t.Status);
 }
Example #5
0
 public static Transfer CreateOfferToSeller(
     Selling offer, Guid sellerId, string note)
 {
     Transfer t = new Transfer();
       t.FromTransferParticipant = new TransferParticipant();
       t.FromTransferParticipant.SellingOfferId = offer.SellingId;
       t.ToTransferParticipant = new TransferParticipant();
       t.ToTransferParticipant.UserId = sellerId;
       t.Amount = offer.Price;
       t.Note = note;
       t.Status = TransferStatus.Completed;
       return t;
 }
Example #6
0
 public static int AddSuggested(int buyingOfferId, int suggested)
 {
     int res = BuyingDataAdapter.AddSuggested(buyingOfferId, suggested);
       if (res == 1)
       {
     Selling o = new Selling().Load<Selling>(SellingDataAdapter.GetOfferById(suggested));
     Buying bo = new Buying().Load<Buying>(BuyingDataAdapter.GetOfferById(buyingOfferId));
     if (o != null && o.SellerId != Guid.Empty && bo != null && bo.BuyerId != Guid.Empty)
     {
       var u = UsersFacade.GetUser(o.SellerId);
       var msg = MessageFactory.CreateByTemplate(MessageTemplate.SellingSuggested, bo.BuyerId,
     null, new[] { o.Title, u == null ? string.Empty : u.UserName, bo.Title });
       MessageFacade.AddFromSystemUser(msg);
     }
       }
       return res;
 }
Example #7
0
 public string Upsert(Selling offer, int buyingId)
 {
     string result = string.Empty;
       if (null != offer)
       {
     offer.SellerId = Credentials.UserId;
     if (offer.SellingId > 0)
     {
       try
       {
     LoadSellingImageData(offer);
     SellingFacade.Update(offer);
     result = CommonResources.UpdateOfferSuccess;
       }
       catch (Exception e)
       {
     result = CommonResources.UpdateOfferFailure;
     throw AssistLogger.Log<ExceptionHolder>(e);
       }
     }
     else
     {
       try
       {
     LoadSellingImageData(offer);
     var o = SellingFacade.AddOffer(offer);
     if(buyingId > 0 && null != o)
     {
       BuyingFacade.AddSuggested(buyingId, o.SellingId);
     }
     result = CommonResources.AddOfferSuccess;
       }
       catch (Exception e)
       {
     result = CommonResources.AddOfferFailure;
     throw AssistLogger.Log<ExceptionHolder>(e);
       }
     }
       }
       else
       {
     throw AssistLogger.Log<ExceptionHolder>(new NullReferenceException());
       }
       return result;
 }
Example #8
0
        public static int AbandonOffer(Selling offer, Guid userId)
        {
            if (offer == null || offer.SellingId < 0 || userId == Guid.Empty || offer.SellerId == Guid.Empty)
            {
            throw new ArgumentNullException();
            }

            int res = SellingDataAdapter.AbandonOfferBuyer(offer.SellingId, userId);

            if (res == 1)
            {
            var user = UsersFacade.GetUser(userId);
            if (user != null)
            {
                var msg = MessageFactory.CreateByTemplate(MessageTemplate.SellingBuyerAbandon, offer.SellerId,
                             null, new[] { user.UserName, offer.Title });
                MessageFacade.AddFromSystemUser(msg);
            }
            }

            return res;
        }
Example #9
0
 public static Selling AddOffer(Guid? userId, int? productCategoryId)
 {
     MembershipUser user = (true == userId.HasValue)
       ? UsersFacade.GetUser(userId.Value)
       : UsersFacadeHelper.GetRandomUser(null);
       Assert.IsNotNull(user);
       Selling o = new Selling();
       o.SellerId = user.UserId();
       o.GameServerId = TypeConverter.ToInt32(Dictionaries.Instance.GameServers.Rows[0][GameServerFields.GameServerId]);
       Random rnd = new Random((int)DateTime.Now.Ticks);
       o.Price = rnd.Next(1, 10);
       Guid g = Guid.NewGuid();
       o.Title = string.Format("Title {0}", g);
       o.Description = string.Format("Description {0}", g);
       o.TransactionPhase = TransactionPhase.Start;
       o.Image = new SellingImage() { Data = Resources.Image1.ToBytes(), ImageName = "Image1" };
       o.ProductCategoryId = productCategoryId.HasValue == true
     ? productCategoryId.Value
     : DictionariesHelper.GetRandomDictionaryEntryId(DictionaryTypes.ProductCategory,ProductCategoryFields.ProductCategoryId);
       if(o.ProductCategoryId == 4)
       {
     o.ProductCategoryMisc = "test product category";
       }
       int historyId;
       Selling no = SellingFacade.Add(o, out historyId);
       SellingImage nsi = SellingFacade.GetImageBySellingId(no.SellingId);
       Assert.AreEqual(o.Image.ImageName, nsi.ImageName);
       Assert.AreEqual(o.Image.Data.Length, nsi.Data.Length);
       Assert.AreEqual(no.SellingId, nsi.SellingId);
       Assert.IsNotNull(no);
       Assert.Greater(historyId, 0);
       Assert.GreaterOrEqual(no.SellingId, 1);
       Assert.AreEqual(no.DeliveryTime, 1);
       Assert.AreEqual(o.ProductCategoryId, no.ProductCategoryId);
       Assert.AreEqual(o.ProductCategoryMisc, no.ProductCategoryMisc);
       Trace.WriteLine(no.ToXmlString());
       return no;
 }
Example #10
0
        public static int ValidOffer(Selling offer, string key, out int historyId)
        {
            if (offer == null || offer.SellingId < 0)
              {
            throw new ArgumentNullException();
              }

              return SellingDataAdapter.ValidOffer(offer.SellingId, key, out historyId);
        }
Example #11
0
 public static Selling Add(Selling o, out int historyId)
 {
     return new Selling().Load<Selling>(SellingDataAdapter.Add(o, out historyId));
 }
Example #12
0
 public static int ValidOffer(Selling offer, string key)
 {
     int temp;
       return ValidOffer(offer, key, out temp);
 }
Example #13
0
 static void AddSuggested(out Buying bo, out Selling o)
 {
     bo = AddOffer(null);
       var seller = UsersFacadeHelper.GetRandomUser(new[] {bo.BuyerId});
       o = SellingFacadeHelper.AddOffer(seller.UserId(), null);
       o.GameServerId = bo.GameServerId;
       SellingFacade.Update(o);
       Thread.Sleep(1000);
       int res = BuyingFacade.AddSuggested(bo.BuyingOfferId, o.SellingId);
       Assert.AreEqual(res, 1);
 }
Example #14
0
 public static int UpdateOfferKey(Selling offer)
 {
     int temp;
       return UpdateOfferKey(ref offer, out temp);
 }
Example #15
0
        public static int UpdateOfferKey(ref Selling offer, out int historyId)
        {
            if (offer == null || offer.SellingId < 0)
              {
            throw new ArgumentNullException();
              }

              DataRow row;
              int res = SellingDataAdapter.UpdateOfferKey(offer.SellingId, GenerateKey(7), out historyId, out row);

              if (row != null)
              {
            offer = offer.Load<Selling>(row);
              }

              return res;
        }
Example #16
0
        public static int ConfirmOffer(ref Selling offer, out int historyId)
        {
            if (offer == null || offer.SellingId < 0 || offer.BuyerId == Guid.Empty || offer.SellerId == Guid.Empty)
              {
            throw new ArgumentNullException();
              }

              DataRow row;
              int res = SellingDataAdapter.ConfirmOffer(offer.SellingId, GenerateKey(7)
              , TransferFactory.CreateBuyerToOffer(offer.BuyerId, offer, string.Empty)
              , out historyId, out row);
              if (res == 1)
              {
            var user = UsersFacade.GetUser(offer.BuyerId);
            if (user != null)
            {
              var msg = MessageFactory.CreateByTemplate(MessageTemplate.SellingConfirmed, offer.SellerId,
            null, new[] { user.UserName, offer.Title });
              MessageFacade.AddFromSystemUser(msg);
            }
              }

              if (row != null)
              {
            offer = offer.Load<Selling>(row);
              }

              return res;
        }
Example #17
0
 public static int ConflictOffer(Selling offer, Guid conflictUserId)
 {
     int temp;
       return ConflictOffer(ref offer, conflictUserId, out temp);
 }
Example #18
0
        public static int DelStartOffer(Selling offer, out int historyId)
        {
            if (offer == null || offer.SellingId < 0 || offer.SellerId == Guid.Empty)
              {
            throw new ArgumentNullException();
              }

              Dictionary<Guid, int> buyers = SellingFacade.GetOfferBuyers(offer.SellingId);

              int res = SellingDataAdapter.DeleteOffer(offer, out historyId);
              if (res == 1)
              {
            if (buyers != null && buyers.Count > 0)
            {
              var user = UsersFacade.GetUser(offer.SellerId);
              if (user != null)
              {
            foreach (KeyValuePair<Guid, int> kvp in buyers)
            {
              if (kvp.Value == 1 || kvp.Value == 4)
              {
                var msg = MessageFactory.CreateByTemplate(MessageTemplate.SellingDeleted, kvp.Key,
                  null, new[] { offer.Title, user.UserName });
                MessageFacade.AddFromSystemUser(msg);
              }
            }
              }
            }
              }
              return res;
        }
Example #19
0
 private void LoadSellingImageData(Selling s)
 {
     if (null != s && null != s.Image && false == string.IsNullOrEmpty(s.Image.ImageName))
       {
     var fullFilePath = GT.Ajax.Controls.FileUploader.GetFullFilePath(Credentials, s.Image.ImageName);
     if (true == File.Exists(fullFilePath))
     {
       s.Image.Data = File.ReadAllBytes(fullFilePath);
     }
       }
 }
Example #20
0
 public static int DelStartOffer(Selling offer)
 {
     int temp;
       return DelStartOffer(offer, out temp);
 }
Example #21
0
        public static int DelFinishOffer(Selling offer, out int historyId)
        {
            if (offer == null || offer.SellingId < 0)
              {
            throw new ArgumentNullException();
              }

              return SellingDataAdapter.DeleteOffer(offer, out historyId);
        }
Example #22
0
 public static int DelFinishOffer(Selling offer)
 {
     int temp;
       return DelFinishOffer(offer, out temp);
 }
Example #23
0
 public static Selling AddOffer(Selling o)
 {
     int temp;
       return Add(o, out temp);
 }
Example #24
0
 public static int ConfirmOffer(Selling offer)
 {
     int temp;
       return ConfirmOffer(ref offer, out temp);
 }
Example #25
0
 public static int CancelConfirmedOffer(Selling offer)
 {
     int temp;
       return CancelConfirmedOffer(ref offer, out temp);
 }
Example #26
0
        public static int ConflictOffer(ref Selling offer, Guid conflictUserId, out int historyId)
        {
            if (offer == null || offer.SellingId < 0 || offer.BuyerId == Guid.Empty
            || offer.SellerId == Guid.Empty || conflictUserId == Guid.Empty)
              {
            throw new ArgumentNullException();
              }

              if (conflictUserId != offer.SellerId && conflictUserId != offer.BuyerId)
              {
            throw new ArgumentException();
              }

              DataRow row;
              int res = SellingDataAdapter.ConflictOffer(offer.SellingId, conflictUserId, out historyId, out row);
              if (res == 1)
              {
            var conflictUser = UsersFacade.GetUser(conflictUserId);
            var msg = MessageFactory.CreateByTemplate(MessageTemplate.SellingConflicted, offer.SellerId,
            null, new[] { offer.Title, conflictUser.UserName });
            //to seller
            MessageFacade.AddFromSystemUser(msg);
            //to buyer
            msg.RecipientId = offer.BuyerId;
            MessageFacade.AddFromSystemUser(msg);
              }

              if (row != null)
              {
            offer = offer.Load<Selling>(row);
              }

              return res;
        }
Example #27
0
 public static int AcceptOffer(Selling offer, Guid userId)
 {
     int temp;
       return AcceptOffer(ref offer, userId, out temp);
 }
Example #28
0
 public static Selling Update(Selling o)
 {
     int temp;
       return Update(o, out temp);
 }
Example #29
0
 public static int FinishOffer(Selling offer)
 {
     int temp;
       return FinishOffer(ref offer, out temp);
 }
Example #30
0
 public static int CancelOfferAccept(Selling offer, Guid cancelUserId)
 {
     int temp;
       return CancelOfferAccepted(ref offer, cancelUserId, out temp);
 }