public async Task <IActionResult> OnPostDeleteBilliardClubAsync(string returnUrl = null)
        {
            returnUrl = returnUrl ?? Url.Content("~/ViewBilliardClub/");

            BillardAppDatabaseInitializer _dbinit    = new BillardAppDatabaseInitializer();
            BillardAppIdentityDbContext   _dbContext = new BillardAppIdentityDbContext(_dbinit.setupOptions().Options);
            var clubForDelete = _dbContext.BilliardClubs.SingleOrDefault(club => club.id == Id);

            var clubNotifications = from e in _dbContext.BilliardClubNotifications
                                    where e.ForBilliardCLub == Id
                                    select e;

            var clubMembers = from e in _dbContext.BilliardClubUsersReference
                              where e.BilliardClubId == Id
                              select e;

            _dbContext.BilliardClubNotifications.RemoveRange(clubNotifications);
            _dbContext.BilliardClubs.Remove(clubForDelete);
            _dbContext.BilliardClubUsersReference.RemoveRange(clubMembers);

            int res = await _dbContext.SaveChangesAsync();

            if (res != 0)
            {
                Console.WriteLine("info: Billiard club deleted successfully!");
                StatusMessage = "Billiard club deleted successfully!";
            }

            return(LocalRedirect(returnUrl));
        }
        public async Task <IActionResult> OnPostJoinRequestAsync(int notificationId, string returnUrl = null)
        {
            returnUrl = returnUrl ?? Url.Content("~/ViewBilliardClub/" + Id);
            BillardAppDatabaseInitializer _dbinit    = new BillardAppDatabaseInitializer();
            BillardAppIdentityDbContext   _dbContext = new BillardAppIdentityDbContext(_dbinit.setupOptions().Options);

            BilliardClubNotifications notification = _dbContext.BilliardClubNotifications.Single(e => e.id == notificationId);

            var user = _dbContext.Users.Single(e => e.Id == notification.userId);

            BilliardClubUserReference billiardClubUser = new BilliardClubUserReference {
                BilliardAppUserId = user.Id,
                BilliardClubId    = Id,
                Approved          = 1
            };

            if (_dbContext.BilliardClubUsersReference.Find(user.Id, Id) != null)
            {
                StatusMessage = user.Name + " " + user.LastName + " is already a member!!";
                return(LocalRedirect(returnUrl));
            }
            _dbContext.BilliardClubUsersReference.Add(billiardClubUser);

            await _dbContext.SaveChangesAsync();

            StatusMessage = user.Name + " " + user.LastName + " is approved!";

            return(LocalRedirect(returnUrl));
        }
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            returnUrl = returnUrl ?? Url.Content("~/Identity/Account/Manage/ViewBillardAppUserEquipment");
            BillardAppDatabaseInitializer _dbinit    = new BillardAppDatabaseInitializer();
            BillardAppIdentityDbContext   _dbContext = new BillardAppIdentityDbContext(_dbinit.setupOptions().Options);

            var result = _dbContext.BillardAppUserEquipment.
                         SingleOrDefault(equipment => equipment.id == Input.id);

            if (result != null)
            {
                result.Name        = Input.Name;
                result.Description = Input.Description;
                result.Price       = Input.Price;
                result.Website     = Input.Website;
            }

            int res = await _dbContext.SaveChangesAsync();

            if (res != 0)
            {
                Console.WriteLine("\n\ninfo: User's selected 'Equipment' is UPDATED!");
                StatusMessage = "Item Updated successfully!";
            }
            return(LocalRedirect(returnUrl));
        }
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            returnUrl = returnUrl ?? Url.Content("~/ViewBilliardClub/" + Id);
            BillardAppDatabaseInitializer _dbinit    = new BillardAppDatabaseInitializer();
            BillardAppIdentityDbContext   _dbContext = new BillardAppIdentityDbContext(_dbinit.setupOptions().Options);
            var result = _dbContext.BilliardClubs.
                         SingleOrDefault(equipment => equipment.id == Id);

            if (result != null)
            {
                result.Name        = Input.Name;
                result.Description = Input.Description;
                result.Origin      = Input.Origin;
                result.Website     = Input.Website;
                result.Address     = Input.Address;
                result.Latitude    = Input.Latitude;
                result.Longitude   = Input.Longitude;
            }
            int res = await _dbContext.SaveChangesAsync();

            if (res != 0)
            {
                Console.WriteLine("\n\ninfo: User's selected " + Input.Name + " is UPDATED!");
                StatusMessage = Input.Name + " Updated successfully!";
            }
            return(LocalRedirect(returnUrl));
        }
        public async Task <IActionResult> OnPostDeleteNotificationAsync(int notificationId, string returnUrl = null)
        {
            returnUrl = returnUrl ?? Url.Content("~/ViewBilliardClub/" + Id);
            BillardAppDatabaseInitializer _dbinit    = new BillardAppDatabaseInitializer();
            BillardAppIdentityDbContext   _dbContext = new BillardAppIdentityDbContext(_dbinit.setupOptions().Options);
            var result = _dbContext.BilliardClubNotifications.
                         SingleOrDefault(notif => notif.id == notificationId);

            _dbContext.BilliardClubNotifications.Remove(result);
            int res = await _dbContext.SaveChangesAsync();

            if (res != 0)
            {
                Console.WriteLine("info: Notification deleted successfully!");
                StatusMessage = "Notification deleted successfully!";
            }
            return(LocalRedirect(returnUrl));
        }
        public async Task <IActionResult> OnPostDelete(int Id, string returnUrl = null)
        {
            returnUrl = returnUrl ?? Url.Content("~/Identity/Account/Manage/ViewBillardAppUserEquipment");
            BillardAppDatabaseInitializer _dbinit    = new BillardAppDatabaseInitializer();
            BillardAppIdentityDbContext   _dbContext = new BillardAppIdentityDbContext(_dbinit.setupOptions().Options);
            var equipment = from eq in _dbContext.BillardAppUserEquipment
                            where eq.id.Equals(Id)
                            select eq;

            _dbContext.BillardAppUserEquipment.Remove(equipment.First());
            int result = await _dbContext.SaveChangesAsync();

            if (result != 0)
            {
                Console.WriteLine("\n\ninfo: User's selected 'Equipment' deleted!");
                StatusMessage = "Item deleted successfully!";
            }
            return(LocalRedirect(returnUrl));
        }
Ejemplo n.º 7
0
        /*
         *      public async Task<IActionResult> UploadImage (IFormFile file) {
         *          var user = await _userManager.GetUserAsync (User);
         *
         *          if (file == null || file.Length == 0) {
         *              return NotFound ($"No Image file specified!");
         *          }
         *          var path = Path.Combine (Directory.GetCurrentDirectory (), "wwwroot", user.UserName, file.Name);
         *          using (var stream = new FileStream (path, FileMode.Create)) {
         *              await file.CopyToAsync (stream);
         *          }
         *
         *      }
         */
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            returnUrl = returnUrl ?? Url.Content("~/Identity/Account/Manage/ViewBillardAppUserEquipment");
            var user = await _userManager.GetUserAsync(User);

            //var path = "";
            if (user == null)
            {
                return(NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'."));
            }
            string imagePath = "None";

            if (Input.Upload != null)
            {
                Directory.CreateDirectory(Path.Combine(_environment.ContentRootPath, "wwwroot", "images", user.Name + user.LastName + user.Id));
                var file = Path.Combine(_environment.ContentRootPath, "wwwroot", "images", user.Name + user.LastName + user.Id, Input.Upload.FileName);
                imagePath = "~/images/" + user.Name + user.LastName + user.Id + "/" + Input.Upload.FileName;
                using (var fileStream = new FileStream(file, FileMode.Create)) {
                    await Input.Upload.CopyToAsync(fileStream);
                }
                Console.WriteLine(imagePath);
            }
            var userEquipment = new BillardAppUserEquipment {
                Name        = Input.Name,
                Description = Input.Description,
                Website     = Input.Website,
                Price       = Input.Price,
                Photo       = imagePath,
                Owner       = user.UserName
            };
            BillardAppDatabaseInitializer _dbinit    = new BillardAppDatabaseInitializer();
            BillardAppIdentityDbContext   _dbContext = new BillardAppIdentityDbContext(_dbinit.setupOptions().Options);

            _dbContext.BillardAppUserEquipment.Add(userEquipment);
            int result = await _dbContext.SaveChangesAsync();

            if (result != 0)
            {
                _logger.LogInformation("Equipment added to " + user.UserName + "!");
            }
            return(LocalRedirect(returnUrl));
        }
Ejemplo n.º 8
0
        public async Task <IActionResult> OnGetJoinRequestAsync(string returnUrl = null)
        {
            BillardAppDatabaseInitializer _dbinit    = new BillardAppDatabaseInitializer();
            BillardAppIdentityDbContext   _dbContext = new BillardAppIdentityDbContext(_dbinit.setupOptions().Options);

            var user = await _userManager.GetUserAsync(User);

            _dbContext.BilliardClubNotifications.Add(new BilliardClubNotifications {
                Type            = NotificationType.JoinRequest,
                Description     = user.Name + ' ' + user.LastName + " wishes to join, approval is required!",
                ForBilliardCLub = Id,
                CreatedDate     = DateTime.Now,
                userId          = user.Id
            });
            await _dbContext.SaveChangesAsync();

            StatusMessage = "Your request is sent and is being reviewed!";
            returnUrl     = returnUrl ?? Url.Content("~/BilliardClub/" + Id);
            return(LocalRedirect(returnUrl));
        }
Ejemplo n.º 9
0
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            BillardAppDatabaseInitializer _dbinit    = new BillardAppDatabaseInitializer();
            BillardAppIdentityDbContext   _dbContext = new BillardAppIdentityDbContext(_dbinit.setupOptions().Options);

            returnUrl = returnUrl ?? Url.Content("~/ViewBilliardClub/" + _billiardEvent.forBilliardClub.ToString());

            var approveEvent = _dbContext.BilliardEvents.Single(e => e.id == Id);

            if (approveEvent.Approved == 1)
            {
                StatusMessage = "Tournament is already approved!!";
            }
            else
            {
                approveEvent.Approved = 1;
                await _dbContext.SaveChangesAsync();

                StatusMessage = "Tournament is approved successfully!";
            }
            return(LocalRedirect(returnUrl));
        }
Ejemplo n.º 10
0
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            BillardAppDatabaseInitializer _dbinit    = new BillardAppDatabaseInitializer();
            BillardAppIdentityDbContext   _dbContext = new BillardAppIdentityDbContext(_dbinit.setupOptions().Options);

            returnUrl = returnUrl ?? Url.Content("~/BilliardClub/" + Id);

            var user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                return(NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'."));
            }
            string imagePath = "None";

            if (Input.Photo != null)
            {
                Directory.CreateDirectory(Path.Combine(_environment.ContentRootPath, "wwwroot", "images", user.Name + user.LastName + user.Id));
                var file = Path.Combine(_environment.ContentRootPath, "wwwroot", "images", user.Name + user.LastName + user.Id, Input.Photo.FileName);
                imagePath = "~/images/" + user.Name + user.LastName + user.Id + "/" + Input.Photo.FileName;
                using (var fileStream = new FileStream(file, FileMode.Create)) {
                    await Input.Photo.CopyToAsync(fileStream);
                }
                Console.WriteLine(imagePath);
            }
            BillardApp.Areas.Identity.Data.BilliardClubNotifications notifications = new BillardApp.Areas.Identity.Data.BilliardClubNotifications {
                Type            = NotificationType.EventRequest,
                Description     = user.Name + ' ' + user.LastName + " has made an event! Approval is required!",
                ForBilliardCLub = Id,
                eventId         = 0
            };

            _billiardClub = _dbContext.BilliardClubs.Single(e => e.id == Id);

            BilliardEvents billiardEvent = new BilliardEvents {
                Owner            = user.UserName,
                Name             = Input.Name,
                Description      = Input.Description,
                Address          = _billiardClub.Address,
                Latitude         = _billiardClub.Latitude,
                Longitude        = _billiardClub.Longitude,
                Photo            = imagePath,
                CreatedDate      = DateTime.Now,
                EventStartDate   = Input.EventStartDate,
                ParticipationFee = Input.ParticipationFee,
                NumberOfPlayers  = Input.NumberOfPlayers,
                forBilliardClub  = Id,
                Approved         = 0
            };

            _dbContext.BilliardEvents.Add(billiardEvent);
            _dbContext.BilliardClubNotifications.Add(notifications);
            await _dbContext.SaveChangesAsync();

            StatusMessage = "Event created successfully! You will have to wait until the event is validated!";

            BillardApp.Areas.Identity.Data.BilliardClubNotifications refactorNotification =
                _dbContext.BilliardClubNotifications.Last();
            BilliardEvents refactorEvent = _dbContext.BilliardEvents.Last();

            refactorNotification.eventId = refactorEvent.id;

            await _dbContext.SaveChangesAsync();

            return(LocalRedirect(returnUrl));
        }
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            returnUrl = returnUrl ?? Url.Content("~/");

            var user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                return(NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'."));
            }
            string imagePath = "None";

            if (Input.Upload != null)
            {
                Directory.CreateDirectory(Path.Combine(_environment.ContentRootPath, "wwwroot", "images", user.Name + user.LastName + user.Id));
                var file = Path.Combine(_environment.ContentRootPath, "wwwroot", "images", user.Name + user.LastName + user.Id, Input.Upload.FileName);
                imagePath = "~/images/" + user.Name + user.LastName + user.Id + "/" + Input.Upload.FileName;
                using (var fileStream = new FileStream(file, FileMode.Create)) {
                    await Input.Upload.CopyToAsync(fileStream);
                }
                Console.WriteLine(imagePath);
            }
            BillardApp.Areas.Identity.Data.BilliardClubNotifications notifications = new BillardApp.Areas.Identity.Data.BilliardClubNotifications {
                Type            = NotificationType.Created,
                Description     = Notifications.BILLIARD_CLUB_CREATED_0 + " '" + Input.Name + "' " + Notifications.BILLIARD_CLUB_CREATED_1 + " Update it's full address so it's easier to find it!",
                ForBilliardCLub = 0
            };

            BilliardClub billiardClub = new BilliardClub {
                Name            = Input.Name,
                Description     = Input.Description,
                Origin          = Input.Origin,
                Owner           = user.UserName,
                Photo           = imagePath,
                Website         = Input.Website,
                NotificationsFk = 0
            };

            BillardAppDatabaseInitializer _dbinit    = new BillardAppDatabaseInitializer();
            BillardAppIdentityDbContext   _dbContext = new BillardAppIdentityDbContext(_dbinit.setupOptions().Options);

            _dbContext.BilliardClubs.Add(billiardClub);
            _dbContext.BilliardClubNotifications.Add(notifications);
            await _dbContext.SaveChangesAsync();

            BilliardClub refactorBilliardClub = _dbContext.BilliardClubs.Last();

            BillardApp.Areas.Identity.Data.BilliardClubNotifications refactorNotifications = _dbContext.BilliardClubNotifications.Last();
            refactorBilliardClub.NotificationsFk  = refactorNotifications.id;
            refactorNotifications.ForBilliardCLub = refactorBilliardClub.id;

            BilliardClubUserReference billiardClubUser = new BilliardClubUserReference {
                BilliardAppUserId = user.Id,
                BilliardClubId    = refactorBilliardClub.id,
                Approved          = 1
            };

            _dbContext.BilliardClubUsersReference.Add(billiardClubUser);

            await _dbContext.SaveChangesAsync();

            return(LocalRedirect(returnUrl));
        }