Esempio n. 1
0
        public async Task <IActionResult> OnPostUpgrade()
        {
            var claimsIdentity = (ClaimsIdentity)this.User.Identity;
            var claim          = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier);


            string value = Request.Cookies[claim.Value + "upgrade"];

            if (value != null)
            {
                StatusMessage = "You have already sent a request to the admins. Only one request can be submitted daily.";
                return(RedirectToPage());
            }

            bool OK = await NotiApi.SendNotiRole(_db, claim.Value);

            if (OK)
            {
                StatusMessage = "Request sent successfully.";
                var           cookie_name = claim.Value + "upgrade";
                CookieOptions option      = new CookieOptions();
                //Testing
                //option.Expires = DateTime.Now.AddSeconds(10);
                option.Expires = DateTime.Now.AddDays(1);
                Response.Cookies.Append(cookie_name, "sended", option);
            }
            else
            {
                StatusMessage = "Administrators are analyzing your request. Excuse us the delay.";
            }


            return(RedirectToPage());
        }
Esempio n. 2
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)));
        }
Esempio n. 3
0
        public async Task <IActionResult> CustomBid(CustomBidViewModel cb)
        {
            if (!ModelState.IsValid)
            {
                return(NotFound());
            }

            var claimsIdentity = (ClaimsIdentity)this.User.Identity;
            var claim          = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier);

            var a_user = await _db.AuctionUser.FirstOrDefaultAsync(a => a.UserId == claim.Value && a.AuctionId == cb.AuctionId);

            var auction = await _db.AuctionHeader.FirstOrDefaultAsync(a => a.Id == cb.AuctionId);

            a_user.LastPriceOffered = cb.CustomBid;

            if (auction.CurrentPrice < a_user.LastPriceOffered)
            {
                var outbided_user = await _db.AuctionUser.FirstOrDefaultAsync(a => a.AuctionId == auction.Id && a.LastPriceOffered == auction.CurrentPrice);

                if (outbided_user.UserId != claim.Value)
                {
                    await NotiApi.SendNotiAuction(_db, "You got outbided, check the auction for more details", outbided_user.UserId, auction.Id);
                }

                await NotiApi.SendNotiAuction(_db, "You bid for $" + a_user.LastPriceOffered.ToString("F2") + " in an auction, check the auction for more details", a_user.UserId, auction.Id);

                auction.CurrentPrice = Math.Max(auction.CurrentPrice, a_user.LastPriceOffered);
            }


            _db.SaveChanges();

            return(RedirectToAction("Details", new { id = cb.AuctionId, status = SD.ActiveStatus, callBack = SD.BidedAuctions }));
        }
Esempio n. 4
0
        public async Task <IActionResult> JoinAuction(int id, string callBack)
        {
            var claimsIdentity = (ClaimsIdentity)this.User.Identity;
            var claim          = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier);

            var au = await _db.AuctionHeader.FirstOrDefaultAsync(a => a.Id == id);


            var a_user = new AuctionUser()
            {
                UserId           = claim.Value,
                AuctionId        = id,
                LastPriceOffered = au.CurrentPrice + au.PriceStep
            };

            if (au.CurrentPrice < a_user.LastPriceOffered)
            {
                var outbided_user = await _db.AuctionUser.FirstOrDefaultAsync(a => a.AuctionId == au.Id && a.LastPriceOffered == au.CurrentPrice);

                if (outbided_user != null)
                {
                    await NotiApi.SendNotiAuction(_db, "You were outbided, check the auction for more details", outbided_user.UserId, au.Id);
                }
                await NotiApi.SendNotiAuction(_db, "You bid for $" + a_user.LastPriceOffered.ToString("F2") + " in an auction, check the auction for more details", a_user.UserId, au.Id);

                au.CurrentPrice = Math.Max(au.CurrentPrice, a_user.LastPriceOffered);
            }



            _db.AuctionUser.Add(a_user);
            _db.SaveChanges();

            return(RedirectToAction("Details", new{ id = id, status = SD.ActiveStatus, callBack = callBack }));
        }
Esempio n. 5
0
        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));
        }
        private async void Close(AuctionHeader auction)
        {
            var winner = await _db.AuctionUser.FirstOrDefaultAsync(u => u.AuctionId == auction.Id && u.LastPriceOffered == auction.CurrentPrice);

            if (winner == null)
            {
                var aproducts = await _db.AuctionProduct.Where(p => p.AuctionId == auction.Id).ToListAsync();

                foreach (AuctionProduct ap in aproducts)
                {
                    ProductSale psale = await _db.ProductSale.Where(ps => ps.ProductId == ap.ProductId && ps.SellerId == auction.SellerId).FirstOrDefaultAsync();

                    if (psale != null)
                    {
                        psale.Units += ap.Quantity;
                        _db.ProductSale.Update(psale);
                    }
                }


                await NotiApi.SendNotiAuction(_db, "Your auction was succefully ignored", auction.SellerId, auction.Id);

                auction.Seen = true;
                _db.AuctionHeader.Update(auction);
            }
            else
            {
                //winner
                await NotiApi.SendNotiAuction(_db, "Congrats! You win the auction " + auction.Id.ToString() + ".", winner.UserId, auction.Id);

                await NotiApi.SendNotiAuction(_db, "Your auction was succefully closed, end value was of $" + auction.CurrentPrice.ToString("F2"), auction.SellerId, auction.Id);

                //Sending Notificaiton to all the losers
                var losers = await _db.AuctionUser.Where(u => u.AuctionId == auction.Id && u.LastPriceOffered < auction.CurrentPrice).ToListAsync();

                foreach (var l in losers)
                {
                    await NotiApi.SendNotiAuction(_db, "You lose the auction " + auction.Id.ToString() + ".", l.UserId, auction.Id);
                }


                auction.Seen = true;
                _db.AuctionHeader.Update(auction);
            }

            // _db.AuctionHeader.Remove(auction);
            _db.SaveChanges();
        }
Esempio n. 7
0
        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" }));
        }
Esempio n. 8
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 }));
        }
Esempio n. 9
0
        public async Task <IActionResult> SummaryPost(OrderDetailsCart model)
        {
            var  claimsIdentity = (ClaimsIdentity)this.User.Identity;
            var  claim          = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier);
            User user           = await _db.User.Where(u => u.Id == claim.Value).FirstOrDefaultAsync();

            OrderDetailsCart detailCart = new OrderDetailsCart()
            {
                listCart    = await _db.ShoppingCart.Where(c => c.UserId == claim.Value).ToListAsync(),
                OrderHeader = new OrderHeader()
                {
                    User       = user,
                    UserId     = claim.Value,
                    TotalPrice = 0,
                    OrderTime  = DateTime.Now
                }
            };

            List <OrderDetails> orderDetailsList = new List <OrderDetails>();

            _db.OrderHeader.Add(detailCart.OrderHeader);
            await _db.SaveChangesAsync();


            foreach (var item in detailCart.listCart)
            {
                ProductSale ps = await _db.ProductSale.Include(p => p.Product).Include(p => p.Seller).Where(p => p.Id == item.ProductSaleID).FirstOrDefaultAsync();

                item.ProductSale = ps;

                OrderDetails orderDetails = new OrderDetails()
                {
                    OrderId     = detailCart.OrderHeader.Id,
                    OrderHeader = detailCart.OrderHeader,
                    ProductId   = item.ProductSaleID,
                    ProductSale = item.ProductSale,
                    Count       = item.Count,
                    Price       = ps.Price,
                    Name        = ps.Product.Name,
                    Description = ps.Product.Description,
                    AmountLeft  = ps.Units
                };

                orderDetailsList.Add(orderDetails);

                detailCart.OrderHeader.TotalPrice += orderDetails.Count * orderDetails.Price;
                _db.OrderDetails.Add(orderDetails);
                ps.Units -= item.Count;
            }

            _db.ShoppingCart.RemoveRange(detailCart.listCart);
            HttpContext.Session.SetInt32(SD.ssShoppingCartCount, 0);

            await _db.SaveChangesAsync();


            //If the purchase was done send Notifications
            await NotiApi.SendNotiBuy(_db, claim.Value, detailCart.OrderHeader, orderDetailsList);

            await NotiApi.SendNotiSells(_db, orderDetailsList);


            return(RedirectToAction("Index", "Home"));
        }
Esempio n. 10
0
        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));
        }