コード例 #1
0
ファイル: Helper.cs プロジェクト: SamirHabota/Watchables
        public void DeleteMovieNotification(Database.Movies movie, string content, string type)
        {
            var cdms = _context.CinemaDayMovie.Where(cdm => cdm.MovieId == movie.MovieId).ToList();

            this.DeleteCdmsNotification(cdms, $"Cinema appointments for the movie '{movie.Title}' have been removed", "Removal");


            var usersMovies = _context.UsersMovies.ToList();
            var hasUsers    = false;

            foreach (var userMovie in usersMovies)
            {
                if (userMovie.MovieId == movie.MovieId)
                {
                    hasUsers = true;
                    break;
                }
            }

            Database.Notifications notification = new Notifications()
            {
                Content = content,
                Type    = type,
                Created = DateTime.Now
            };

            if (hasUsers)
            {
                _context.Notifications.Add(notification);
                _context.SaveChanges();
            }

            foreach (var userMovie in usersMovies)
            {
                if (userMovie.MovieId == movie.MovieId)
                {
                    Database.UsersNotifications not = new UsersNotifications()
                    {
                        Notification = notification,
                        UserId       = userMovie.UserId
                    };
                    _context.UsersNotifications.Add(not);
                    _context.UsersMovies.Remove(userMovie);
                    _context.SaveChanges();
                }
            }

            var rotations = _context.Rotations.ToList();

            foreach (var rotation in rotations)
            {
                if (rotation.MovieId == movie.MovieId)
                {
                    this.DeleteRotationNotification(rotation, $"Rotations with the movie '{movie.Title}' have been removed", "Removal");
                }
            }

            _context.Movies.Remove(movie);
            _context.SaveChanges();
        }
コード例 #2
0
        public async Task <IActionResult> MarkAsSent(int id, string interestedTeamId)
        {
            var donation = _context.Donations.Where(d => d.Id == id && d.InterestedTeamId == interestedTeamId).FirstOrDefault();
            var interestedTeamIdFromDonation = donation.InterestedTeamId;

            donation.Status = "Sent";

            var part = _context.Parts.Where(p => p.Id == donation.PartId).FirstOrDefault();

            part.Status = "NotAvaible";

            var notification = _context.Notifications.Where(n => n.Id == 5).FirstOrDefault();

            UsersNotifications userNotification = new UsersNotifications
            {
                NotificationId = notification.Id,
                ReceptorTeamId = interestedTeamIdFromDonation,
                DeliverTeamId  = donation.DonatorTeamId
            };

            _context.Add(userNotification);

            _context.Update(donation);
            _context.Update(part);
            await _context.SaveChangesAsync();

            return(RedirectToAction("InterestedTeamProfile", "Profile", new { interestedTeamId = interestedTeamIdFromDonation }));
        }
コード例 #3
0
        public async Task <IActionResult> MarkAsReceived(int id, string donatorTeamId)
        {
            var donation = _context.Donations.Where(d => d.Id == id && d.DonatorTeamId == donatorTeamId).FirstOrDefault();
            var donatorTeamIdFromDonation = donation.DonatorTeamId;

            donation.Status = "Received";

            var part = _context.Parts.Where(p => p.Id == donation.PartId).FirstOrDefault();

            part.Status = "NotAvailable";

            var user = _authDbContext.Users.Where(u => u.Id == donatorTeamId).FirstOrDefault();

            user.NumberOfSuccessDonations = user.NumberOfSuccessDonations + 1;

            var notification = _context.Notifications.Where(n => n.Id == 6).FirstOrDefault();

            UsersNotifications userNotification = new UsersNotifications
            {
                NotificationId = notification.Id,
                ReceptorTeamId = donatorTeamIdFromDonation,
                DeliverTeamId  = donation.InterestedTeamId
            };

            _context.Update(donation);
            _context.Update(part);
            _authDbContext.Update(user);

            await _context.SaveChangesAsync();

            await _authDbContext.SaveChangesAsync();

            return(RedirectToAction("InterestedTeamProfile", "Profile", new { interestedTeamId = donatorTeamIdFromDonation }));
        }
コード例 #4
0
ファイル: Helper.cs プロジェクト: SamirHabota/Watchables
        public void DeleteShowNotification(Database.Shows show, string content, string type)
        {
            var usersShows = _context.UsersShows.ToList();
            var hasUsers   = false;

            foreach (var usersShow in usersShows)
            {
                if (usersShow.ShowId == show.ShowId)
                {
                    hasUsers = true;
                    break;
                }
            }

            Database.Notifications notification = new Notifications()
            {
                Content = content,
                Type    = type,
                Created = DateTime.Now
            };

            if (hasUsers)
            {
                _context.Notifications.Add(notification);
                _context.SaveChanges();
            }

            foreach (var usersShow in usersShows)
            {
                if (usersShow.ShowId == show.ShowId)
                {
                    Database.UsersNotifications not = new UsersNotifications()
                    {
                        Notification = notification,
                        UserId       = usersShow.UserId
                    };
                    _context.UsersNotifications.Add(not);
                    _context.UsersShows.Remove(usersShow);
                    _context.SaveChanges();
                }
            }

            var rotations = _context.Rotations.ToList();

            foreach (var rotation in rotations)
            {
                if (rotation.ShowId == show.ShowId)
                {
                    this.DeleteRotationNotification(rotation, $"Rotations with the show '{show.Title}' have been removed", "Removal");
                }
            }


            _context.Shows.Remove(show);
            _context.SaveChanges();
        }
コード例 #5
0
        public override Order Insert(InsertOrderRequest request)
        {
            Database.Orders order = new Orders();
            order.Total         = request.NumberOfTickets * request.Appointment.Price;
            order.UserId        = request.UserId;
            order.AppointmentId = request.Appointment.AppointmentId;
            foreach (var product in request.Products)
            {
                order.Total += product.Price;
                Database.OrderProducts newItem = new OrderProducts()
                {
                    Order     = order,
                    ProductId = product.ProductId
                };
                _context.OrderProducts.Add(newItem);
            }
            Helper helper = new Helper(_context);

            for (var i = 0; i < request.NumberOfTickets; i++)
            {
                Database.Tickets newTicket = new Tickets()
                {
                    DateTime = DateTime.Now,
                    Order    = order,
                    Seat     = helper.RandomString(5)
                };
                _context.Tickets.Add(newTicket);
            }

            _context.Orders.Add(order);
            _context.Appointments.Find(request.Appointment.AppointmentId).SoldSeats += request.NumberOfTickets;
            _context.SaveChanges();

            var app = _context.Appointments.Include(a => a.CinemaDayMovie).ThenInclude(cdm => cdm.Movie).Single(a => a.AppointmentId == request.Appointment.AppointmentId);

            Database.Notifications notification = new Notifications()
            {
                Created = DateTime.Now,
                Type    = "Order",
                Content = $"{_context.Users.Find(request.UserId).FirstName} {_context.Users.Find(request.UserId).LastName} placed an order for '{app.CinemaDayMovie.Movie.Title}' of {order.Total}"
            };
            _context.Notifications.Add(notification);
            Database.UsersNotifications not = new UsersNotifications()
            {
                Notification = notification,
                UserId       = request.UserId
            };
            _context.UsersNotifications.Add(not);
            _context.SaveChanges();

            return(_mapper.Map <Model.Order>(order));
        }
コード例 #6
0
ファイル: Helper.cs プロジェクト: SamirHabota/Watchables
        public void NonDeleteNotification(List <Database.Appointments> apps, string content, string type)
        {
            bool hasOrders = false;
            var  orders    = _context.Orders.ToList();

            foreach (var app in apps)
            {
                foreach (var order in orders)
                {
                    if (order.AppointmentId == app.AppointmentId)
                    {
                        hasOrders = true;
                        break;
                    }
                }
                if (hasOrders)
                {
                    break;
                }
            }

            Database.Notifications notification = new Notifications()
            {
                Content = content,
                Type    = type,
                Created = DateTime.Now
            };

            if (hasOrders)
            {
                _context.Notifications.Add(notification);
                _context.SaveChanges();
            }

            foreach (var app in apps)
            {
                foreach (var order in orders)
                {
                    if (order.AppointmentId == app.AppointmentId)
                    {
                        Database.UsersNotifications not = new UsersNotifications()
                        {
                            Notification = notification,
                            UserId       = order.UserId
                        };
                        _context.UsersNotifications.Add(not);
                        _context.SaveChanges();
                    }
                }
            }
        }
コード例 #7
0
        public async Task <IActionResult> Create(int id)
        {
            if (ModelState.IsValid)
            {
                var interestedTeamId = this.User.FindFirstValue(ClaimTypes.NameIdentifier);
                var interestedTeam   = await _authDbContext.Users
                                       .FirstOrDefaultAsync(u => u.Id == interestedTeamId);

                var interestedTeamName = interestedTeam.TeamName;

                var part = await _context.Parts.FindAsync(id);

                var donatorTeam = await _authDbContext.Users
                                  .FirstOrDefaultAsync(u => u.Id == part.OwnerTeam);

                var donatorTeamId   = donatorTeam.Id;
                var donatorTeamName = donatorTeam.TeamName;

                Donation donation = new Donation
                {
                    NamePart           = part.Name,
                    ImagePart          = part.Image,
                    Part               = part,
                    Status             = "Requested",
                    InterestedTeamId   = interestedTeamId,
                    InterestedTeamName = interestedTeamName,
                    DonatorTeamId      = donatorTeamId,
                    DonatorTeamName    = donatorTeamName
                };

                var notification = _context.Notifications.Where(n => n.Id == 1).FirstOrDefault();

                UsersNotifications userNotification = new UsersNotifications
                {
                    NotificationId = notification.Id,
                    ReceptorTeamId = donatorTeamId,
                    DeliverTeamId  = interestedTeamId
                };

                _context.Add(userNotification);
                _context.Add(donation);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            return(View());
        }
コード例 #8
0
ファイル: Helper.cs プロジェクト: SamirHabota/Watchables
        public void DeleteProductNotification(Database.Products product, string content, string type)
        {
            var  orderProducts = _context.OrderProducts.ToList();
            bool hasOrders     = false;

            foreach (var orderProduct in orderProducts)
            {
                if (orderProduct.ProductId == product.ProductId)
                {
                    hasOrders = true;
                    break;
                }
            }

            Database.Notifications notification = new Notifications()
            {
                Content = content,
                Type    = type,
                Created = DateTime.Now
            };

            if (hasOrders)
            {
                _context.Notifications.Add(notification);
                _context.SaveChanges();
            }

            foreach (var orderProduct in orderProducts)
            {
                if (orderProduct.ProductId == product.ProductId)
                {
                    var order = _context.Orders.Find(orderProduct.OrderId);
                    order.Total -= product.Price;
                    Database.UsersNotifications not = new UsersNotifications()
                    {
                        Notification = notification,
                        UserId       = order.UserId
                    };
                    _context.UsersNotifications.Add(not);
                    _context.OrderProducts.Remove(orderProduct);
                    _context.SaveChanges();
                }
            }
            _context.Products.Remove(product);
            _context.SaveChanges();
        }
コード例 #9
0
ファイル: Helper.cs プロジェクト: SamirHabota/Watchables
        public void DeleteSubscriptionNotification(Database.Subscriptions subscription, string content, string type)
        {
            var usersSubscriptions = _context.UsersSubscriptions.ToList();
            var hasUsers           = false;

            foreach (var usersSubscription in usersSubscriptions)
            {
                if (usersSubscription.SubscriptionId == subscription.SubscriptionId)
                {
                    hasUsers = true;
                    break;
                }
            }

            Database.Notifications notification = new Notifications()
            {
                Content = content,
                Type    = type,
                Created = DateTime.Now
            };

            if (hasUsers)
            {
                _context.Notifications.Add(notification);
                _context.SaveChanges();
            }

            foreach (var usersSubscription in usersSubscriptions)
            {
                if (usersSubscription.SubscriptionId == subscription.SubscriptionId)
                {
                    Database.UsersNotifications not = new UsersNotifications()
                    {
                        Notification = notification,
                        UserId       = usersSubscription.UserId
                    };
                    _context.UsersNotifications.Add(not);
                    _context.UsersSubscriptions.Remove(usersSubscription);
                    _context.SaveChanges();
                }
            }
            _context.Subscriptions.Remove(subscription);
            _context.SaveChanges();
        }
コード例 #10
0
ファイル: Helper.cs プロジェクト: SamirHabota/Watchables
        public void ChangeAppointmentNotification(Database.Appointments app, string content, string type, decimal oldPrice, decimal newPrice)
        {
            bool hasOrder = false;

            foreach (var order in _context.Orders.ToList())
            {
                if (order.AppointmentId == app.AppointmentId)
                {
                    hasOrder = true;
                    break;
                }
            }


            Database.Notifications notification = new Notifications()
            {
                Content = content,
                Type    = type,
                Created = DateTime.Now
            };

            if (hasOrder)
            {
                _context.Notifications.Add(notification);
                _context.SaveChanges();
            }

            foreach (var order in _context.Orders.ToList())
            {
                if (order.AppointmentId == app.AppointmentId)
                {
                    order.Total -= oldPrice;
                    order.Total += newPrice;
                    Database.UsersNotifications not = new UsersNotifications()
                    {
                        Notification = notification,
                        UserId       = order.UserId
                    };
                    _context.UsersNotifications.Add(not);
                    _context.SaveChanges();
                }
            }
        }
コード例 #11
0
        public async Task <IActionResult> DeleteConfirmed(int id)
        {
            var donation = await _context.Donations.FindAsync(id);

            var notification = _context.Notifications.Where(n => n.Id == 2).FirstOrDefault();

            UsersNotifications userNotification = new UsersNotifications
            {
                NotificationId = notification.Id,
                ReceptorTeamId = donation.DonatorTeamId,
                DeliverTeamId  = donation.InterestedTeamId
            };

            _context.Add(userNotification);
            _context.Donations.Remove(donation);
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
コード例 #12
0
ファイル: Helper.cs プロジェクト: SamirHabota/Watchables
        public void DeleteOrderNotification(int orderId, string content, string type)
        {
            Database.Notifications notification = new Notifications()
            {
                Content = content,
                Created = DateTime.Now,
                Type    = type
            };
            _context.Notifications.Add(notification);
            _context.SaveChanges();

            var order = _context.Orders.Find(orderId);

            Database.UsersNotifications not = new UsersNotifications()
            {
                Notification = notification,
                UserId       = order.UserId
            };
            _context.UsersNotifications.Add(not);
            _context.SaveChanges();

            foreach (var ticket in _context.Tickets.ToList())
            {
                if (ticket.OrderId == order.OrderId)
                {
                    _context.Tickets.Remove(ticket);
                    _context.SaveChanges();
                }
            }

            foreach (var orderProduct in _context.OrderProducts.ToList())
            {
                if (orderProduct.OrderId == order.OrderId)
                {
                    _context.OrderProducts.Remove(orderProduct);
                    _context.SaveChanges();
                }
            }

            _context.Orders.Remove(order);
            _context.SaveChanges();
        }
コード例 #13
0
ファイル: Helper.cs プロジェクト: SamirHabota/Watchables
        public void ChangeRotationNotification(Database.Rotations rotation, string content, string type)
        {
            var  usersRotations = _context.UsersRotations.ToList();
            bool hasUsers       = false;

            foreach (var userRotation in usersRotations)
            {
                if (userRotation.RotationId == rotation.RotationId)
                {
                    hasUsers = true;
                    break;
                }
            }

            Database.Notifications notification = new Notifications()
            {
                Content = content,
                Type    = type,
                Created = DateTime.Now
            };

            if (hasUsers)
            {
                _context.Notifications.Add(notification);
                _context.SaveChanges();
            }
            foreach (var userRotation in usersRotations)
            {
                if (userRotation.RotationId == rotation.RotationId)
                {
                    Database.UsersNotifications not = new UsersNotifications()
                    {
                        Notification = notification,
                        UserId       = userRotation.UserId
                    };
                    _context.UsersNotifications.Add(not);
                    _context.SaveChanges();
                }
            }
        }
コード例 #14
0
ファイル: Helper.cs プロジェクト: SamirHabota/Watchables
        public void DeleteAppointmentsNotification(List <Database.Appointments> apps, string content, string type)
        {
            var  orders        = _context.Orders.ToList();
            var  tickets       = _context.Tickets.ToList();
            var  orderProducts = _context.OrderProducts.ToList();
            bool hasOrders     = false;

            foreach (var app in apps)
            {
                foreach (var order in orders)
                {
                    if (order.AppointmentId == app.AppointmentId)
                    {
                        hasOrders = true;
                        break;
                    }
                }
                if (hasOrders)
                {
                    break;
                }
            }

            Database.Notifications notification = new Notifications()
            {
                Content = content,
                Type    = type,
                Created = DateTime.Now
            };

            if (hasOrders)
            {
                _context.Notifications.Add(notification);
                _context.SaveChanges();
            }

            foreach (var app in apps)
            {
                foreach (var order in orders)
                {
                    if (order.AppointmentId == app.AppointmentId)
                    {
                        Database.UsersNotifications not = new UsersNotifications()
                        {
                            Notification = notification,
                            UserId       = order.UserId
                        };
                        _context.UsersNotifications.Add(not);
                        _context.SaveChanges();
                        foreach (var ticket in tickets)
                        {
                            if (ticket.OrderId == order.OrderId)
                            {
                                _context.Tickets.Remove(ticket);
                                _context.SaveChanges();
                            }
                        }
                        foreach (var orderProduct in orderProducts)
                        {
                            if (orderProduct.OrderId == order.OrderId)
                            {
                                _context.OrderProducts.Remove(orderProduct);
                                _context.SaveChanges();
                            }
                        }
                        _context.Orders.Remove(order);
                        _context.SaveChanges();
                    }
                }
                _context.Appointments.Remove(app);
            }
        }
コード例 #15
0
        public List <UsersNotifications> Get(string emails)
        {
            UsersNotifications UsersList = new UsersNotifications();

            return(UsersList.getUsers(emails));
        }
コード例 #16
0
 public void Post([FromBody] UsersNotifications u)
 {
     u.InsertUsersNotifications();
 }
コード例 #17
0
ファイル: UserService.cs プロジェクト: SamirHabota/Watchables
        public string DeleteItem(Delete delete)
        {
            bool validUser = false;

            foreach (var user in _context.Users.ToList())
            {
                if (user.UserId == delete.UserId)
                {
                    validUser = true;
                    break;
                }
            }
            if (!validUser)
            {
                throw new UserException("The user could not be found");
            }

            Database.Notifications notification = new Notifications()
            {
                Created = DateTime.Now,
                Type    = "Removal"
            };
            Database.UsersNotifications not = new UsersNotifications()
            {
                UserId = delete.UserId
            };

            if (delete.Item == global::BuyItem.Movie)
            {
                var inBase = _context.UsersMovies.Where(i => i.MovieId == delete.ItemId && i.UserId == i.UserId).Single();
                if (inBase == null)
                {
                    throw new UserException("Movie could not be found");
                }
                _context.UsersMovies.Remove(inBase);
                _context.SaveChanges();
                return("Movie deleted");
            }

            else if (delete.Item == global::BuyItem.Show)
            {
                var inBase = _context.UsersShows.Where(i => i.ShowId == delete.ItemId && i.UserId == i.UserId).Single();
                if (inBase == null)
                {
                    throw new UserException("Show could not be found");
                }
                _context.UsersShows.Remove(inBase);
                _context.SaveChanges();
                return("Show deleted");
            }

            else if (delete.Item == global::BuyItem.Subscription)
            {
                var inBase = _context.UsersSubscriptions.Where(i => i.SubscriptionId == delete.ItemId && i.UserId == i.UserId).Single();
                if (inBase == null)
                {
                    throw new UserException("Subscription could not be found");
                }
                _context.UsersSubscriptions.Remove(inBase);
                notification.Content = $"{_context.Users.Find(delete.UserId).FirstName} {_context.Users.Find(delete.UserId).LastName} canceled a subscription of {_context.Subscriptions.Find(delete.ItemId).Price}";
                _context.Notifications.Add(notification);
                not.Notification = notification;
                _context.UsersNotifications.Add(not);
                _context.SaveChanges();
                return("Subscription deleted");
            }

            else
            {
                var inBase = _context.UsersRotations.Where(i => i.RotationId == delete.ItemId && i.UserId == i.UserId).Single();
                if (inBase == null)
                {
                    throw new UserException("Rotation could not be found");
                }
                _context.UsersRotations.Remove(inBase);
                _context.SaveChanges();
                return("Rotation deleted");
            }
        }
コード例 #18
0
ファイル: Helper.cs プロジェクト: SamirHabota/Watchables
        public void DeleteRotationNotification(Database.Rotations rotation, string content, string type)
        {
            var usersRotations = _context.UsersRotations.ToList();
            var hasUsers       = false;

            foreach (var usersRotation in usersRotations)
            {
                if (usersRotation.RotationId == rotation.RotationId)
                {
                    hasUsers = true;
                    break;
                }
            }

            Database.Notifications notification = new Notifications()
            {
                Content = content,
                Type    = type,
                Created = DateTime.Now
            };

            var  notifications = _context.Notifications.ToList();
            bool sameNot       = false;
            var  notId         = 0;

            foreach (var n in notifications)
            {
                if (n.Content == content)
                {
                    sameNot = true;
                    notId   = n.NotificationId;
                    break;
                }
            }

            if (hasUsers && !sameNot)
            {
                _context.Notifications.Add(notification);
                _context.SaveChanges();
            }


            foreach (var usersRotation in usersRotations)
            {
                if (usersRotation.RotationId == rotation.RotationId)
                {
                    Database.UsersNotifications not = new UsersNotifications()
                    {
                        UserId = usersRotation.UserId
                    };
                    if (sameNot)
                    {
                        not.NotificationId = notId;
                    }
                    else
                    {
                        not.Notification = notification;
                    }
                    _context.UsersNotifications.Add(not);
                    _context.UsersRotations.Remove(usersRotation);
                    _context.SaveChanges();
                }
            }
            _context.Rotations.Remove(rotation);
            _context.SaveChanges();
        }
コード例 #19
0
ファイル: UserService.cs プロジェクト: SamirHabota/Watchables
        public string BuyItem(Buy buy)
        {
            bool validUser = false;

            foreach (var user in _context.Users.ToList())
            {
                if (user.UserId == buy.UserId)
                {
                    validUser = true;
                    break;
                }
            }
            if (!validUser)
            {
                throw new UserException("The user could not be found");
            }

            Database.Notifications notification = new Notifications()
            {
                Created = DateTime.Now,
                Type    = "Add"
            };
            Database.UsersNotifications not = new UsersNotifications()
            {
                UserId = buy.UserId
            };


            if (buy.Item == global::BuyItem.Movie)
            {
                bool valid = false;
                foreach (var item in _context.Movies.ToList())
                {
                    if (item.MovieId == buy.ItemId)
                    {
                        valid = true;
                        break;
                    }
                }
                if (!valid)
                {
                    throw new UserException("The movie could not be found");
                }


                Database.UsersMovies newMovie = new Database.UsersMovies {
                    MovieId        = buy.ItemId,
                    UserId         = buy.UserId,
                    PurchaseDate   = DateTime.Now,
                    PurchaseAmount = _context.Movies.Find(buy.ItemId).Price
                };
                _context.UsersMovies.Add(newMovie);
                notification.Content = $"{_context.Users.Find(buy.UserId).FirstName} {_context.Users.Find(buy.UserId).LastName} bought the movie '{_context.Movies.Find(buy.ItemId).Title}'";
                _context.Notifications.Add(notification);
                not.Notification = notification;
                _context.UsersNotifications.Add(not);
                _context.SaveChanges();
                return("Movie bought!");
            }
            else if (buy.Item == global::BuyItem.Show)
            {
                bool valid = false;
                foreach (var item in _context.Shows.ToList())
                {
                    if (item.ShowId == buy.ItemId)
                    {
                        valid = true;
                        break;
                    }
                }
                if (!valid)
                {
                    throw new UserException("The show could not be found");
                }


                Database.UsersShows newShow = new Database.UsersShows()
                {
                    ShowId         = buy.ItemId,
                    UserId         = buy.UserId,
                    PurchaseDate   = DateTime.Now,
                    PurchaseAmount = _context.Shows.Find(buy.ItemId).Price
                };
                _context.UsersShows.Add(newShow);
                notification.Content = $"{_context.Users.Find(buy.UserId).FirstName} {_context.Users.Find(buy.UserId).LastName} bought the show '{_context.Shows.Find(buy.ItemId).Title}'";
                _context.Notifications.Add(notification);
                not.Notification = notification;
                _context.UsersNotifications.Add(not);
                _context.SaveChanges();

                return("Show bought!");
            }
            else if (buy.Item == global::BuyItem.Subscription)
            {
                bool valid = false;
                foreach (var item in _context.Subscriptions.ToList())
                {
                    if (item.SubscriptionId == buy.ItemId)
                    {
                        valid = true;
                        break;
                    }
                }
                if (!valid)
                {
                    throw new UserException("The subscription could not be found");
                }


                Database.UsersSubscriptions newSubscription = new Database.UsersSubscriptions()
                {
                    SubscriptionId   = buy.ItemId,
                    UserId           = buy.UserId,
                    SubscriptionDate = DateTime.Now
                };
                _context.UsersSubscriptions.Add(newSubscription);


                notification.Content = $"{_context.Users.Find(buy.UserId).FirstName} {_context.Users.Find(buy.UserId).LastName} subscribed for {_context.Subscriptions.Find(buy.ItemId).Price}";
                _context.Notifications.Add(notification);
                not.Notification = notification;
                _context.UsersNotifications.Add(not);
                _context.SaveChanges();
                return("Subscription bought!");
            }

            else
            {
                bool valid = false;
                foreach (var item in _context.Rotations.ToList())
                {
                    if (item.RotationId == buy.ItemId)
                    {
                        valid = true;
                        break;
                    }
                }
                if (!valid)
                {
                    throw new UserException("The rotation could not be found");
                }


                Database.UsersRotations newRotation = new UsersRotations()
                {
                    RotationId      = buy.ItemId,
                    UserId          = buy.UserId,
                    RotationClaimed = DateTime.Now
                };
                _context.UsersRotations.Add(newRotation);
                var rotation = _context.Rotations.Include(r => r.Movie).Include(r => r.Show).Single(r => r.RotationId == buy.ItemId);
                notification.Content = $"{_context.Users.Find(buy.UserId).FirstName} {_context.Users.Find(buy.UserId).LastName} claimed the rotation '{rotation.Movie.Title} / {rotation.Show.Title}'";
                _context.Notifications.Add(notification);
                not.Notification = notification;
                _context.UsersNotifications.Add(not);
                _context.SaveChanges();

                return("Rotation bought!");
            }
        }
コード例 #20
0
        public int Get(string email, string phone, string token)
        {
            UsersNotifications User = new UsersNotifications(email, phone, token);

            return(User.checkUser());
        }