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); }
public static Offer RejectOffer(ApplicationDbContext db, Guid offerId, IPrincipal user) { Offer offer = db.Offers.Find(offerId); AppUser appUser = AppUserHelpers.GetAppUser(db, user); offer.OfferStatus = OfferStatusEnum.Rejected; offer.RejectedBy = appUser.AppUserId; offer.RejectedOn = DateTime.Now; db.Entry(offer).State = EntityState.Modified; db.SaveChanges(); //set any related actions to Closed NotificationHelpers.RemoveNotificationsForOffer(db, offerId, user); return(offer); }