Beispiel #1
0
        public async Task <IActionResult> DeleteConfirmed(string id)
        {
            var user = await _db.User.FindAsync(id);

            var currentDate = DateTime.Now;
            var auctions    = await _db.AuctionHeader.Where(a => a.SellerId == user.Id &&
                                                            a.BeginDate <= currentDate && a.EndDate >= currentDate)
                              .ToListAsync();

            var msg = "The auction created by " + user.Name + ", in which you were participating, was cancelled.";

            foreach (var item in auctions)
            {
                var users = await _db.AuctionUser.Where(a => a.AuctionId == item.Id).ToListAsync();

                foreach (var u in users)
                {
                    NotiApi.SendNotification(_db, u.UserId, msg, currentDate);
                }
            }

            _db.User.Remove(user);
            await _db.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
        public async Task <IActionResult> Dismiss(int?id, string type)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var noti = await _db.Notification.FirstOrDefaultAsync(n => n.Id == id);

            if (noti == null)
            {
                return(NotFound());
            }

            if ((noti as NotiRole) != null)
            {
                var noti_role = noti as NotiRole;
                var m         = "You request of becoming a seller got denied";
                NotiApi.SendNotification(_db, noti_role.UserID, m);
            }

            _db.Notification.Remove(noti);
            await _db.SaveChangesAsync();



            return(RedirectToAction("Index", "Notification", type));
        }
        public async Task <IActionResult> AcceptRequest(int id)
        {
            var noti_role = await _db.NotiRole.FirstOrDefaultAsync(n => n.Id == id);

            var customerID = noti_role.UserID;
            var customer   = await _db.User.FirstOrDefaultAsync(u => u.Id == customerID);


            var new_seller = new Seller()
            {
                Id                 = customerID,
                Name               = customer.Name,
                UserName           = customer.UserName,
                NormalizedUserName = customer.NormalizedUserName,
                Email              = customer.Email,
                NormalizedEmail    = customer.NormalizedEmail,
                EmailConfirmed     = true,
                PasswordHash       = customer.PasswordHash,
                LockoutEnabled     = true,
                SecurityStamp      = customer.SecurityStamp
            };



            _db.Remove(customer);
            await _db.SaveChangesAsync();

            _db.Seller.Add(new_seller);

            var seller_role = await _db.Roles.FirstOrDefaultAsync(r => r.Name == SD.SellerUser);

            var seller_role_id = seller_role.Id;

            _db.UserRoles.Add(new IdentityUserRole <string>()
            {
                RoleId = seller_role_id,
                UserId = new_seller.Id
            });

            await _db.SaveChangesAsync();

            var message = "Congrats!!! You have been promoted to a Seller!!!";

            NotiApi.SendNotification(_db, new_seller.Id, message);

            return(RedirectToAction("Dismiss", "Notification", new { id = id, type = "NotiRole" }));
        }
Beispiel #4
0
        public async Task <IActionResult> DeleteAuction(int id, string userId, string callBack, string status)
        {
            var claimsIdentity = (ClaimsIdentity)this.User.Identity;
            var claim          = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier);

            var auction = await _db.AuctionHeader.Include(a => a.User).Where(a => a.Id == id).FirstOrDefaultAsync();

            if (auction == null)
            {
                return(NotFound());
            }

            var currentDate = DateTime.Now;
            var adminMsg    = "You have succesfully deleted one of " + auction.User.Name + " auctions.";

            NotiApi.SendNotification(_db, claim.Value, adminMsg, currentDate);
            NotiApi.SendNotification(_db, auction.SellerId, "One of your auctions was deleted by an admin of the application", currentDate);

            var products = await _db.AuctionProduct.Where(a => a.AuctionId == id).ToListAsync();

            foreach (var ap in products)
            {
                ProductSale psale = await _db.ProductSale.Where(ps => ps.ProductId == ap.ProductId && ps.SellerId == auction.SellerId).FirstAsync();

                psale.Units += ap.Quantity;
                _db.ProductSale.Update(psale);
            }
            var users = await _db.AuctionUser.Where(a => a.AuctionId == id).ToListAsync();

            if (users != null)
            {
                var msg = "The auction created by " + auction.User.Name + ", which had a total of "
                          + products.Count().ToString() + " products and in which you were participating, was cancelled.";
                foreach (var user in users)
                {
                    NotiApi.SendNotification(_db, user.UserId, msg, currentDate);
                }
                _db.AuctionUser.RemoveRange(users);
            }
            _db.AuctionProduct.RemoveRange(products);
            _db.AuctionHeader.Remove(auction);

            await _db.SaveChangesAsync();

            return(RedirectToAction("Auctions", new{ id = userId, status = status, callBack = callBack }));
        }
        public async Task <IActionResult> DismissAll(string type)
        {
            var claimsIdentity = (ClaimsIdentity)this.User.Identity;
            var claim          = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier);

            bool is_admin = this.User.IsInRole(SD.ManagerUser);


            if (type == "NotiRole" || type == null)
            {
                var notifications = await _db.NotiRole
                                    .Where(n =>
                                           n.SendToUser == claim.Value ||
                                           (n.SendToUser == "All_A" && is_admin)
                                           )
                                    .ToListAsync();

                foreach (var noti in notifications)
                {
                    if ((noti as NotiRole) != null)
                    {
                        var noti_role = noti as NotiRole;
                        var m         = "You request of becoming a seller got denied";
                        NotiApi.SendNotification(_db, noti_role.UserID, m);
                    }
                }

                _db.RemoveRange(notifications);
            }

            if (type == "NotiBuy" || type == null)
            {
                var notifications = await _db.NotiBuy
                                    .Where(n =>
                                           n.SendToUser == claim.Value
                                           )
                                    .ToListAsync();

                _db.RemoveRange(notifications);
            }

            if (type == "NotiSell" || type == null)
            {
                var notifications = await _db.NotiSell
                                    .Where(n =>
                                           n.SendToUser == claim.Value
                                           )
                                    .ToListAsync();

                _db.RemoveRange(notifications);
            }

            if (type == "NotiGeneral" || type == null)
            {
                var notifications = await _db.Notification.Where(n => n is Notification && n.SendToUser == claim.Value).ToListAsync();

                _db.RemoveRange(notifications);
            }

            if (type == "NotiAuction" || type == null)
            {
                var notifications = await _db.NotiAuction
                                    .Where(n =>
                                           n.SendToUser == claim.Value
                                           )
                                    .ToListAsync();

                _db.RemoveRange(notifications);
            }

            await _db.SaveChangesAsync();

            return(RedirectToAction("Index", "Notification", type));
        }