Ejemplo n.º 1
0
        public static Offer UpdateOffer(ApplicationDbContext db, Guid offerid, OfferStatusEnum offerStatus, decimal?currentOfferQuantity, decimal?counterOfferQuantity, IPrincipal user)
        {
            Offer offer = OfferHelpers.GetOffer(db, offerid);

            switch (offerStatus)
            {
            case OfferStatusEnum.Reoffer:     //update offer value and move counter value to previous
                if (currentOfferQuantity.HasValue)
                {
                    offer.CurrentOfferQuantity         = currentOfferQuantity.Value;
                    offer.PreviousCounterOfferQuantity = offer.CounterOfferQuantity;
                    offer.CounterOfferQuantity         = null;
                    offer.LastOfferOriginatorAppUserId = AppUserHelpers.GetAppUserIdFromUser(user);
                    offer.LastOfferOriginatorDateTime  = DateTime.Now;
                    offer.OfferStatus = offerStatus;

                    db.Entry(offer).State = EntityState.Modified;
                    db.SaveChanges();
                }
                break;

            case OfferStatusEnum.Countered:     //update counter value and move current offer to previous offer
                if (counterOfferQuantity.HasValue)
                {
                    offer.CounterOfferQuantity  = counterOfferQuantity;
                    offer.PreviousOfferQuantity = offer.CurrentOfferQuantity;
                    offer.CurrentOfferQuantity  = 0.00M;
                    if (!offer.CounterOfferOriginatorOrganisationId.HasValue)
                    {
                        AppUser appUser = AppUserHelpers.GetAppUser(db, AppUserHelpers.GetAppUserIdFromUser(user));
                        offer.CounterOfferOriginatorAppUserId      = appUser.AppUserId;
                        offer.CounterOfferOriginatorDateTime       = DateTime.Now;
                        offer.CounterOfferOriginatorOrganisationId = appUser.OrganisationId;
                    }
                    else
                    {
                        offer.LastCounterOfferOriginatorAppUserId = AppUserHelpers.GetAppUserIdFromUser(user);
                        offer.LastCounterOfferOriginatorDateTime  = DateTime.Now;
                    }
                    offer.OfferStatus = offerStatus;

                    db.Entry(offer).State = EntityState.Modified;
                    db.SaveChanges();
                }
                break;
            }
            //Create Action
            Organisation org = OrganisationHelpers.GetOrganisation(db, AppUserHelpers.GetAppUser(db, AppUserHelpers.GetAppUserIdFromUser(user)).OrganisationId);

            NotificationHelpers.CreateNotification(db, NotificationTypeEnum.NewOfferReceived, "New offer received from " + org.OrganisationName, offer.OfferId, offer.ListingOriginatorAppUserId.Value, offer.ListingOriginatorOrganisationId.Value, user);

            return(offer);
        }
Ejemplo n.º 2
0
        public static Offer UpdateStatus(ApplicationDbContext db, Guid offerId, OfferStatusEnum newStatus, IPrincipal user)
        {
            Offer offer = OfferHelpers.GetOffer(db, offerId);

            offer.OfferStatus = newStatus;

            if (newStatus == OfferStatusEnum.ClosedNoStock)
            {
                offer.ClosedNoStockBy = AppUserHelpers.GetAppUserIdFromUser(user);
                offer.ClosedNoStockOn = DateTime.Now;
            }

            db.Entry(offer).State = EntityState.Modified;
            db.SaveChanges();

            return(offer);
        }