Example #1
0
 public AuctionController(InBidEntities entities)
 {
     InBidEntities = entities;
 }
Example #2
0
        //Override IsValid
        protected override ValidationResult IsValid(object value,ValidationContext validationContext)
        {
            //Get PropertyInfo Object
             InBidEntities = new InBidEntities();

            var basePropertyInfo = validationContext.ObjectType.GetProperty(_basePropertyName);
            var AuctionId = (int)basePropertyInfo.GetValue(validationContext.ObjectInstance, null);

            var basePropertyInfoStartPrice = validationContext.ObjectType.GetProperty(_basePropertyStartPrice);
            var StartPrice = (decimal)basePropertyInfoStartPrice.GetValue(validationContext.ObjectInstance, null);

            var ChangeCurrentPrice = (Decimal)value;
               // InBidEntities.SaveChanges();
            var auction = InBidEntities.Auctions.Where(x => x.AuctionId == AuctionId).SingleOrDefault();
            decimal MinJump = auction.MinJump;
            decimal CurrentPrice = auction.CurrentPrice;
            decimal AuctionStartPrice = auction.StartPrice;
            bool Direction = auction.Direction;
            var offers = InBidEntities.Offers.Where(x => x.AuctionId == AuctionId);

            if (offers.Count() > 0)
            {
                if (Direction) //aukcja w dół
                {

                    if ((ChangeCurrentPrice == 0)&&(StartPrice==0))
                    {
                        return null;
                    }
                    //edycja oferty
                    if (ChangeCurrentPrice > 0)
                    {
                        //za mała zmiana Zmiana obecnej ceny jest miniejsza od minimalnego skoku
                        if ((CurrentPrice - ChangeCurrentPrice < MinJump) || (CurrentPrice < ChangeCurrentPrice))
                        {
                            var message = FormatErrorMessage(validationContext.DisplayName);
                            return new ValidationResult(message);
                        }
                    }
                    if (StartPrice > 0)
                    {
                        //za mała oferta Wartość Oferty nie spełna warunków aukcji
                        ChangeCurrentPrice = StartPrice;
                        if ((CurrentPrice - ChangeCurrentPrice < MinJump) || (CurrentPrice < ChangeCurrentPrice))
                        {
                            var message = FormatErrorMessage(validationContext.DisplayName);
                            return new ValidationResult(message);
                        }
                    }
                }
               //dodawanie oferty
                else
                {

                    if ((ChangeCurrentPrice == 0) && (StartPrice == 0))
                    {
                        return null;
                    }
                    //edycja oferty
                    if (ChangeCurrentPrice > 0)
                    {
                        //za mała zmiana Zmiana obecnej ceny jest miniejsza od minimalnego skoku
                        if ((-(CurrentPrice - ChangeCurrentPrice) < MinJump) || (CurrentPrice > ChangeCurrentPrice))
                        {
                            var message = FormatErrorMessage(validationContext.DisplayName);
                            return new ValidationResult(message);
                        }
                    }
                    if (StartPrice > 0)
                    {
                        //za mała oferta Wartość Oferty nie spełna warunków aukcji
                        ChangeCurrentPrice = StartPrice;
                        if ((-(CurrentPrice - ChangeCurrentPrice) < MinJump) || (CurrentPrice > ChangeCurrentPrice))
                        {
                            var message = FormatErrorMessage(validationContext.DisplayName);
                            return new ValidationResult(message);
                        }
                    }
                }
            }
            else //dodawanie pierwzej oferty
            {
                if (Direction) //aukcja malejąca
                {
                        ChangeCurrentPrice = StartPrice;
                        if ((CurrentPrice - ChangeCurrentPrice < 0) || (ChangeCurrentPrice > AuctionStartPrice) )
                        {
                            //dodawanie pierwszej oferty mnijeszej od aktualnej ceny
                            var message = FormatErrorMessage(validationContext.DisplayName);
                            return new ValidationResult(message);
                        }
                }
                else //aukcja rosnąca
                {
                    ChangeCurrentPrice = StartPrice;
                    if ((-(CurrentPrice - ChangeCurrentPrice) < 0) || (ChangeCurrentPrice < AuctionStartPrice))
                        {
                            //dodawanie pierwszej oferty wiekszej od aktualnej ceny
                            var message = FormatErrorMessage(validationContext.DisplayName);
                            return new ValidationResult(message);
                        }
                }

            }

            //Actual comparision

            //Default return - This means there were no validation error
            return null;
        }
Example #3
0
 public OfferController(InBidEntities entities)
 {
     InBidEntities = entities;
 }