Exemplo n.º 1
0
        public async Task <IActionResult> RejectLot(LotModerationModel model)
        {
            if (ModelState.IsValid)
            {
                await crudLotLogic.Update(new AuctionLot
                {
                    Id     = model.AuctionLot.Id,
                    Status = LotStatusProvider.GetRejectedStatus()
                });

                await crudNoteLogic.Delete(new Note
                {
                    AuctionLotId = model.AuctionLot.Id
                });

                await crudNoteLogic.Create(new Note
                {
                    AuctionLotId = model.AuctionLot.Id,
                    Text         = model.RejectNote
                });
                await SendRejectMessage(model.AuctionLot.Id, model.RejectNote);

                return(View("Redirect", new RedirectModel
                {
                    InfoMessages = RedirectionMessageProvider.LotRejectedMessages(),
                    SecondsToRedirect = ApplicationConstantsProvider.GetLongRedirectionTime(),
                    RedirectUrl = "/Moderator/Lots"
                }));
            }
            model.Expanded = true;
            return(View("CheckLot", model));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> CreateLot(CreateLotViewModel model)
        {
            if (ModelState.IsValid)
            {
                AuctionLot toAdd = new AuctionLot
                {
                    Name = model.Name,
                    User = new User
                    {
                        UserName = User.Identity.Name
                    },
                    Description = model.Description,
                    StartDate   = model.StartDate.Value,
                    EndDate     = model.EndDate.Value,
                    PriceInfo   = new PriceInfo
                    {
                        StartPrice   = model.StartPrice.Value,
                        CurrentPrice = model.StartPrice.Value,
                        BidStep      = model.BidStep.Value
                    }
                };

                string dbPhotoPath = $"/images/{User.Identity.Name}/{model.Name}/photo{Path.GetExtension(model.Photo.FileName)}";
                toAdd.PhotoSrc = dbPhotoPath;

                try
                {
                    await lotLogic.Create(toAdd);
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError(string.Empty, ex.Message);
                    return(View(model));
                }

                string physicalDirectory = Path.GetDirectoryName($"{environment.WebRootPath + dbPhotoPath}");
                if (!Directory.Exists(physicalDirectory))
                {
                    Directory.CreateDirectory(physicalDirectory);
                }

                using (FileStream fs = new FileStream($"{environment.WebRootPath + dbPhotoPath}", FileMode.Create))
                {
                    await model.Photo.CopyToAsync(fs);
                }

                return(View("Redirect", new RedirectModel
                {
                    InfoMessages = RedirectionMessageProvider.LotCreatedMessages(),
                    RedirectUrl = "/Home/Lots",
                    SecondsToRedirect = ApplicationConstantsProvider.GetMaxRedirectionTime()
                }));
            }
            return(View(model));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> PlaceBid(string lotId)
        {
            if (!string.IsNullOrWhiteSpace(lotId))
            {
                User user = await userManager.FindByNameAsync(User.Identity.Name);

                try
                {
                    await bidLogic.Create(new Bid
                    {
                        AuctionLot = (await lotLogic.Read(new AuctionLot
                        {
                            Id = lotId
                        }))?.First(),
                        User = user
                    });
                } catch (Exception ex)
                {
                    ModelState.AddModelError(string.Empty, ex.Message);
                    return(View("Redirect", new RedirectModel
                    {
                        InfoMessages = RedirectionMessageProvider.AuctionTimeUpMessages(),
                        RedirectUrl = $"/User/OpenLot/?id={lotId}",
                        SecondsToRedirect = ApplicationConstantsProvider.GetShortRedirectionTime()
                    }));
                }
                AuctionLot lotToAdd = new AuctionLot {
                    Id = lotId
                };
                await savedListLogic.Add(user, lotToAdd);
                await SendNotifications(lotId, User.Identity.Name);

                return(View("Redirect", new RedirectModel
                {
                    InfoMessages = RedirectionMessageProvider.BidPlacedMessages(),
                    RedirectUrl = $"/User/OpenLot/?id={lotId}",
                    SecondsToRedirect = ApplicationConstantsProvider.GetShortRedirectionTime()
                }));
            }
            return(NotFound());
        }