Exemplo n.º 1
0
        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());
        }
Exemplo n.º 2
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));
        }