public static void SendNotification(OffersContext context, Offer offer, Action action) { var offerId = offer.Id; var usrIds = context.SavedOffers.Where(p => p.OfferId == offer.Id).ToList <SavedOffer>(); Notification notification = null; if (action == Action.Update) { notification = new Notification("The offer with following details was modified: Name: " + offer.Name + ", Description: " + offer.Description + ", Price: " + offer.Price, offer.Id); } else if (action == Action.Delete) { notification = new Notification("The offer with following details was deleted: Nume:" + offer.Name + ", Descriere: " + offer.Description + ", Pret: " + offer.Price, null); } context.Notifications.Add(notification); context.SaveChanges(); foreach (var i in usrIds) { var usrNot = new NotificationsToUsers(notification.Id, i.UserId); context.NotificationToUsers.Add(usrNot); context.SaveChanges(); } }
protected Repository(OffersContext context) { this.context = context; }