Esempio n. 1
0
        public static Offer AcceptOffer(ApplicationDbContext db, Guid offerId, IPrincipal user)
        {
            Offer   offer   = db.Offers.Find(offerId);
            AppUser appUser = AppUserHelpers.GetAppUser(db, user);

            Order order = OrderHelpers.CreateOrder(db, offer, user);

            offer.OfferStatus = OfferStatusEnum.Accepted;
            offer.AcceptedBy  = appUser.AppUserId;
            offer.AcceptedOn  = DateTime.Now;
            offer.OrderId     = order.OrderId;
            offer.OrderOriginatorAppUserId      = appUser.AppUserId;
            offer.OrderOriginatorOrganisationId = appUser.OrganisationId;
            offer.OrderOriginatorDateTime       = DateTime.Now;

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

            //set any related actions to Closed
            NotificationHelpers.RemoveNotificationsForOffer(db, offerId, user);

            //set any related current offers to closed if there is no stock left (currentOfferQuantity = 0)
            if (offer.CurrentOfferQuantity == 0)
            {
                OfferHelpers.CloseOffersRelatedToListing(db, offer.ListingId, user);
            }

            //Create Action to show order ready
            Organisation org = OrganisationHelpers.GetOrganisation(db, offer.OfferOriginatorOrganisationId);

            NotificationHelpers.CreateNotification(db, NotificationTypeEnum.NewOrderReceived, "New order received from " + org.OrganisationName, order.OrderId, appUser.AppUserId, org.OrganisationId, user);

            return(offer);
        }
Esempio n. 2
0
        public static Offer AcceptOffer(ApplicationDbContext db, IPrincipal user, Offer offer)
        {
            offer.OfferStatus = OfferStatusEnum.Accepted;

            Order order = OrderHelpers.CreateOrder(db, user, offer);

            offer.OrderId = order.OrderId;
            offer.OrderOriginatorAppUserId = order.OrderOriginatorAppUserId;
            offer.OrderOriginatorBranchId  = order.OrderOriginatorBranchId;
            offer.OrderOriginatorCompanyId = order.OrderOriginatorCompanyId;
            offer.OrderOriginatorDateTime  = order.OrderOriginatorDateTime;

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

            return(offer);
        }