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));
        }
Example #2
0
        public async Task Create(AuctionLot model)
        {
            if (model.User == null || string.IsNullOrWhiteSpace(model.User.UserName))
            {
                throw new Exception("Пользователь не определен");
            }

            if (model.EndDate <= model.StartDate)
            {
                throw new Exception("Дата окончания торгов должна " +
                                    "быть больше даты начала торгов минимум на 1 день");
            }

            AuctionLot sameLot = await context.AuctionLots
                                 .Include(lot => lot.User)
                                 .FirstOrDefaultAsync(lot =>
                                                      lot.User.UserName == model.User.UserName && lot.Name == model.Name);

            if (sameLot != null)
            {
                throw new Exception("Уже есть лот с таким названием");
            }

            model.Status = LotStatusProvider.GetOnModerationStatus();
            model.Id     = Guid.NewGuid().ToString();
            model.User   = await context.Users.FirstAsync(user =>
                                                          user.UserName == model.User.UserName);

            await context.AuctionLots.AddAsync(model);

            await context.SaveChangesAsync();
        }
        public async Task <IActionResult> Lots(int page = 1)
        {
            List <AuctionLot> lotsOnModeration = await paginationLotLogic.GetPage(page, new AuctionLot
            {
                Status = LotStatusProvider.GetOnModerationStatus()
            });

            int lotsCount = await paginationLotLogic.GetCount(new AuctionLot
            {
                Status = LotStatusProvider.GetOnModerationStatus()
            });

            return(View(new AuctionLotsViewModel
            {
                AuctionLots = lotsOnModeration,
                PageViewModel = new PageViewModel(lotsCount, page, ApplicationConstantsProvider.GetPageSize())
            }));
        }
Example #4
0
        public async Task <IActionResult> Lots(int page = 1)
        {
            List <AuctionLot> lotsToDisplay = await lotLogic.GetPage(page, new AuctionLot
            {
                Status = LotStatusProvider.GetAcceptedStatus()
            });

            int lotsCount = await lotLogic.GetCount(new AuctionLot
            {
                Status = LotStatusProvider.GetAcceptedStatus()
            });

            return(View(new AuctionLotsViewModel()
            {
                PageViewModel = new PageViewModel(lotsCount, page, ApplicationConstantsProvider.GetPageSize()),
                AuctionLots = lotsToDisplay
            }));
        }
        public async Task <IActionResult> AcceptLot(string id)
        {
            if (!string.IsNullOrWhiteSpace(id))
            {
                await crudLotLogic.Update(new AuctionLot
                {
                    Id     = id,
                    Status = LotStatusProvider.GetAcceptedStatus()
                });
                await SendAcceptMessage(id);

                return(View("Redirect", new RedirectModel
                {
                    InfoMessages = RedirectionMessageProvider.LotAcceptedMessages(),
                    SecondsToRedirect = ApplicationConstantsProvider.GetLongRedirectionTime(),
                    RedirectUrl = "/Moderator/Lots"
                }));
            }
            return(NotFound());
        }
Example #6
0
 public async Task <IActionResult> EditLot(string id)
 {
     if (!string.IsNullOrWhiteSpace(id))
     {
         AuctionLot lotToEdit = (await lotLogic.Read(new AuctionLot {
             Id = id
         })).First();
         if (lotToEdit.Status == LotStatusProvider.GetRejectedStatus() ||
             lotToEdit.Status == LotStatusProvider.GetAcceptedStatus() &&
             DateTime.Now < lotToEdit.StartDate)
         {
             if (lotToEdit.Status == LotStatusProvider.GetRejectedStatus())
             {
                 ViewBag.RejectNote = "Причина, по которой ваш лот не был опубликован: "
                                      + lotToEdit.Note.Text;
             }
             else
             {
                 ViewBag.RejectNote = string.Empty;
             }
             return(View(new EditLotViewModel
             {
                 Id = lotToEdit.Id,
                 BidStep = lotToEdit.PriceInfo.BidStep,
                 Description = lotToEdit.Description,
                 Name = lotToEdit.Name,
                 OldName = lotToEdit.Name,
                 StartDate = lotToEdit.StartDate,
                 EndDate = lotToEdit.EndDate,
                 StartPrice = lotToEdit.PriceInfo.StartPrice,
                 OldPhotoSrc = lotToEdit.PhotoSrc
             }));
         }
         else
         {
             return(NotFound());
         }
     }
     return(NotFound());
 }
Example #7
0
        public async Task <IActionResult> EditLot(EditLotViewModel model)
        {
            if (ModelState.IsValid)
            {
                if (string.IsNullOrWhiteSpace(model.Id))
                {
                    return(NotFound());
                }

                AuctionLot lotToEdit = new AuctionLot
                {
                    Id          = model.Id,
                    Name        = model.Name,
                    Description = model.Description,
                    StartDate   = model.StartDate.Value,
                    EndDate     = model.EndDate.Value,
                    Status      = LotStatusProvider.GetOnModerationStatus(),
                    PriceInfo   = new PriceInfo
                    {
                        StartPrice = model.StartPrice.Value,
                        BidStep    = model.BidStep.Value
                    }
                };

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

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

                string oldPath = $"{environment.WebRootPath + Path.GetDirectoryName(model.OldPhotoSrc)}";
                if (Directory.Exists(oldPath))
                {
                    Directory.Delete(oldPath, true);
                }

                string newPhysicalDirectory = Path.GetDirectoryName($"{environment.WebRootPath + newDbPath}");

                if (!Directory.Exists(newPhysicalDirectory))
                {
                    Directory.CreateDirectory(newPhysicalDirectory);
                }

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

                return(View("Redirect", new RedirectModel
                {
                    InfoMessages = RedirectionMessageProvider.LotUpdatedMessages(),
                    RedirectUrl = "/Home/Lots",
                    SecondsToRedirect = ApplicationConstantsProvider.GetMaxRedirectionTime()
                }));
            }
            return(View(model));
        }