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)); }
public async Task <IActionResult> ChangePassword(ChangePasswordViewModel model) { if (ModelState.IsValid) { if (model.OldPassword == model.NewPassword) { ModelState.AddModelError(string.Empty, "Новый и старый пароли не должны совпадать"); return(View(model)); } User user = await userManager.FindByNameAsync(User.Identity.Name); user.UserName += ApplicationConstantsProvider.AvoidValidationCode(); user.Email += ApplicationConstantsProvider.AvoidValidationCode(); var changePasswordResult = await userManager.ChangePasswordAsync(user, model.OldPassword, model.NewPassword); if (changePasswordResult.Succeeded) { return(View("Redirect", new RedirectModel { InfoMessages = RedirectionMessageProvider.AccountUpdatedMessages(), RedirectUrl = "/Account/Personal", SecondsToRedirect = ApplicationConstantsProvider.GetShortRedirectionTime() })); } else { ModelState.AddModelError(string.Empty, "Вы ввели неверный старый пароль"); } } return(View(model)); }
public async Task <IActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { if (!string.IsNullOrWhiteSpace(model.TelegramId)) { User sameTelegramUser = (await userLogic.Read(new User { TelegramUsername = model.TelegramId }))?.FirstOrDefault(); if (sameTelegramUser != null) { ModelState.AddModelError(string.Empty, "Уже есть пользователь с таким Telegram-идентификатором"); return(View(model)); } } User user = new User { Email = model.Email, UserName = model.UserName, TelegramUsername = string.IsNullOrWhiteSpace(model.TelegramId) ? string.Empty : model.TelegramId, TelegramChatId = string.Empty }; var registerResult = await userManager.CreateAsync(user, model.Password); if (registerResult.Succeeded) { user.Email += ApplicationConstantsProvider.AvoidValidationCode(); user.UserName += ApplicationConstantsProvider.AvoidValidationCode(); await userManager.AddToRoleAsync(user, "regular user"); await savedListLogic.Create(user); await signInManager.SignInAsync(user, false); return(View("Redirect", new RedirectModel { InfoMessages = RedirectionMessageProvider.AccountCreatedMessages(), RedirectUrl = "/Home/Lots", SecondsToRedirect = ApplicationConstantsProvider.GetShortRedirectionTime() })); } else { foreach (var error in registerResult.Errors) { ModelState.AddModelError(string.Empty, error.Description); } } } return(View(model)); }
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)); }
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()); }
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()); }
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)); }