public IActionResult EditPriceDoesNotIncludes(int id, EditPriceDoesNotIncludesViewModel model) { var success = tours.EditPricePriceDoesNotIncludes(id, model.Content); if (success) { TempData.AddSuccessMessage($"Content price doesn't includes of Tour {id} was edited successfully!"); } else { TempData.AddErrorMessage($"Content price doesn't includes of Tour {id} was not changed"); } return(base.RedirectToAction( nameof(Web.Controllers.ToursController.Details), "Tours", new { area = string.Empty, id = id })); }
public async Task <IActionResult> Delete(int id) { var exists = await tagService.ExistsAsync(id); if (!exists) { TempData.AddErrorMessage("Tag does not exist."); return(RedirectToAction(nameof(Add))); } await tagService.DeleteAsync(id); TempData.AddSuccessMessage(); return(RedirectToAction(nameof(Add))); }
public async Task <IActionResult> MyProducts() { IEnumerable <PurchaseListingModel> products = null; try { products = await _purchaseService.Products(User.Identity.Name); } catch (InvalidOperationException ex) { TempData.AddErrorMessage(ex.Message); return(Redirect(Home)); } return(View(products ?? Enumerable.Empty <PurchaseListingModel>())); }
public IActionResult EditTrip(EditTripViewModel model) { var success = tours.EditTrip(model.Id, model.StartDate, model.EndDate, model.Price); if (success) { TempData.AddSuccessMessage($"Trip {model.Id} was edited successfully!"); } else { TempData.AddErrorMessage($"Trip {model.Id} was not changed"); } return(base.RedirectToAction( nameof(Web.Controllers.ToursController.All), "Tours", new { area = string.Empty, id = model.TourId })); }
public IActionResult EditAdditionalService(int id, EditAdditionalServiceViewModel model) { var success = tours.EditAdditionalService(id, model.ServiceId, model.Content, model.Price); if (success) { TempData.AddSuccessMessage($"Additional service {model.ServiceId} of Tour {id} was edited successfully!"); } else { TempData.AddErrorMessage($"Additional service {model.ServiceId} of Tour {id} was not changed"); } return(base.RedirectToAction( nameof(Web.Controllers.ToursController.Details), "Tours", new { area = string.Empty, id = id })); }
public IActionResult EditUsefulInformation(int id, EditUsefulInformaionViewModel model) { var success = tours.EditUsefulInformation(id, model.Content); if (success) { TempData.AddSuccessMessage($"Useful information of Tour {id} was edited successfully!"); } else { TempData.AddErrorMessage($"Useful information of Tour {id} was not changed"); } return(base.RedirectToAction( nameof(Web.Controllers.ToursController.Details), "Tours", new { area = string.Empty, id = id })); }
public async Task <IActionResult> ChangePassword(string username, UserChangePasswordServiceModel model) { if (!ModelState.IsValid) { return(View(model)); } User user = await this.userManager.FindByNameAsync(username); if (user == null) { TempData.AddErrorMessage(string.Format(EntityNotFound, username)); return(this.RedirectToHomeIndex()); } bool userHasPassword = await this.userManager.HasPasswordAsync(user); if (!userHasPassword) { TempData.AddErrorMessage(UserChangePasswordExternalLoginErrorMessage); return(RedirectToAction(nameof(Profile), new { username })); } bool oldPasswordIsValid = await this.userService.IsOldPasswordValid(user, model.OldPassword); if (!oldPasswordIsValid) { TempData.AddErrorMessage(UserOldPasswordNotValid); return(View(model)); } bool changePasswordResult = await this.userService.ChangePasswordAsync(user, model.OldPassword, model.NewPassword); if (!changePasswordResult) { TempData.AddWarningMessage(EntityNotModified); return(View(model)); } TempData.AddSuccessMessage(UserChangePasswordSuccessMessage); return(RedirectToAction(nameof(Profile), new { username })); }
public async Task <IActionResult> Register(RegisterViewModel model, string returnUrl = null) { if (User.Identity.IsAuthenticated) { return(BadRequest()); } ViewData.SetReturnUrl(returnUrl); var userExists = await this.userManager.FindByNameAsync(model.Email) != null; if (userExists) { TempData.AddErrorMessage(UserErrorConstants.UserExists); return(View(model)); } var user = new User { UserName = model.Email, Email = model.Email, FirstName = model.FirstName, LastName = model.LastName }; if (model.ProfilePicture != null) { user.ProfilePicture = await this.fileService.UploadImageAndGetUrlAsync( model.ProfilePicture, UserDataConstants.ProfilePictureWidth, UserDataConstants.ProfilePictureHeight); user.ProfilePictureNav = await this.fileService.UploadImageAndGetUrlAsync( model.ProfilePicture, UserDataConstants.ProfilePictureNavWidth, UserDataConstants.ProfilePictureNavHeight); } var result = await this.userManager.CreateAsync(user, model.Password); if (!result.Succeeded) { TempData.AddErrorMessage(UserErrorConstants.ErrorCreatingUser); return(View(model)); } await this.signInManager.SignInAsync(user, isPersistent : false); TempData.AddSuccessMessage(string.Format(UserSuccessMessages.RegisterMessage, model.FirstName, model.LastName)); return(RedirectToLocal(returnUrl)); }
public ActionResult Edit(int?id, SubCategoryFormViewModel model) { if (id == null) { return(BadRequest()); } if (!ModelState.IsValid) { model.Categories = this.GetCategories(); return(View(model)); } string oldName = this.subCategoryService.GetName(id.Value); if (oldName == null) { return(BadRequest()); } string newName = model.SubCategory.Name; if (this.subCategoryService.NameExists(newName) && oldName != newName) { model.Categories = this.GetCategories(); TempData.AddErrorMessage(string.Format(WebConstants.EntryExists, newName)); return(View(model)); } bool success = this.subCategoryService.Edit(id.Value, model.CategoryId, newName); if (!success) { return(BadRequest()); } TempData.AddSuccessMessage( string.Format(WebConstants.SuccessfullEntityOperation, SubCategory, WebConstants.Edited)); return(RedirectToAction( nameof(CategoriesController.All), Categories, new { area = WebConstants.ModeratorArea })); }
public async Task <ActionResult> Destroy(int id) { var game = await this.games.FindByIdAsync(id); if (game == null) { return(this.HttpNotFound()); } this.games.Delete(id); TempData.AddErrorMessage($"Game {game.Title} was deleted successful!"); return(this.RedirectToAction(nameof(HomeController.Index), "Home", new { area = string.Empty })); }
public IActionResult Edit(EditProductFormModel model) { if (this._categories.NameById(model.CategoryId) == null) { TempData.AddErrorMessage("Невалидна категория."); return(RedirectToAction("Index", "Home", new { area = "" })); } var uploads = Path.Combine(_hostingEnvironment.WebRootPath, "uploads"); string uniqueFileName = ""; bool image = false; if (model.Image != null) { if (model.Image.Length > 0) { uniqueFileName = this.GetUniqueName(model.Image.FileName); var filePath = Path.Combine(uploads, uniqueFileName); model.Image.CopyTo(new FileStream(filePath, FileMode.Create)); image = true; } } string oldImagePath = this._products.Details(model.Id).Image; if (oldImagePath != "default.jpg") { this.DeleteOldImage(oldImagePath); } if (image) { var result = this._products.Update(model.Id, model.Title, model.Price, model.Description, uniqueFileName, model.CategoryId); } else { var result = this._products.Update(model.Id, model.Title, model.Price, model.Description, oldImagePath, model.CategoryId); } TempData.AddSuccessMessage("Успешно редактирахте продукта."); return(RedirectToAction("Index", "Home", new { area = "" })); }
public async Task <IActionResult> Edit(EditMontlyConsumablesModel model) { if (!ModelState.IsValid) { TempData.AddErrorMessage(WrongInput); return(this.View(model)); } var isEdited = await this.consumables.EditAsync(model); if (!isEdited) { TempData.AddErrorMessage("Редакцията не беше успешна"); return(RedirectToAction("Index")); } TempData.AddErrorMessage("Редакцията беше успешна"); return(RedirectToAction("Index")); }
public async Task <IActionResult> MakeAccountant(string id) { var userToSetAccountant = await this.users.GetUserAsync(id); var result = await this.userManager.AddToRoleAsync(userToSetAccountant, WebConstants.AccountantRole); if (!result.Succeeded) { TempData.AddErrorMessage("Добавянето на ролята счетоводител не беше успешно"); return(Redirect("/Admin/Home/Index")); } var model = await this.users.GetUserWithRolesAsync(id); TempData.AddSuccessMessage("Добавянето на ролята счетоводител беше успешно"); return(View(model)); }
public async Task <IActionResult> Edit(int id, SubcategoryFormViewModel model) { if (!ModelState.IsValid) { model.Categories = await this.GetCategoriesSelectListItems(); return(View(model)); } bool isSubcategoryExistingById = await this.subcategoryService.IsSubcategoryExistingById(id, false); if (!isSubcategoryExistingById) { TempData.AddErrorMessage(string.Format(EntityNotFound, SubcategoryEntity)); return(this.RedirectToSubcategoriesIndex(false)); } bool isSubcategoryModified = await this.managerSubcategoryService.IsSubcategoryModified(id, model.Name, model.CategoryId); if (!isSubcategoryModified) { TempData.AddWarningMessage(EntityNotModified); model.Categories = await this.GetCategoriesSelectListItems(); return(View(model)); } bool isSubcategoryExistingByIdAndName = await this.subcategoryService.IsSubcategoryExistingByIdAndName(id, model.Name); if (isSubcategoryExistingByIdAndName) { TempData.AddErrorMessage(string.Format(EntityExists, SubcategoryEntity)); model.Categories = await this.GetCategoriesSelectListItems(); return(View(model)); } await this.managerSubcategoryService.EditAsync(id, model.Name, model.CategoryId); TempData.AddSuccessMessage(string.Format(EntityModified, SubcategoryEntity)); return(this.RedirectToSubcategoriesIndex(false)); }
public async Task <IActionResult> Delete(int id) { var article = await articlesRepository.FindByIdAsync(id); var user = await userManager.GetUserAsync(User); if ((article.User != null && article.User.Id == user.Id) || User.IsInRole(UserRole.Administrator)) { await articlesRepository.DeleteAsync(article); TempData.AddSuccessMessage("Článek byl odstraněn"); return(RedirectToAction("Index")); } TempData.AddErrorMessage("Nemáte dostatečná oprávnění pro odstranění tohoto článku."); return(RedirectToAction("Detail", new { id })); }
public IActionResult ContractDownload(int id) { bool contractExists = this.profileService.ContractExists(); if (!contractExists) { TempData.AddErrorMessage("The contract is not uploaded. Please contact our team."); return(RedirectToAction("EventDetails", new { id })); } byte[] contractSubmission = this.profileService.GetFirstContractSubmission(); Response.Headers.Add("content-disposition", "attachment; filename=Contract.pdf"); return(File(contractSubmission, "application/pdf")); }
public async Task <IActionResult> AddPhotos(CreateAlbumServiceModel model) { if (!ModelState.IsValid) { TempData.AddErrorMessage(ErrorModelState()); return(View(model)); } if (!User.IsInRole(AuthorRole)) { return(RedirectToAction(HomeIndex)); } await this.albumService.AddPhotoSRVC(model); TempData.AddSuccessMessage(SuccessAddPhoto); return(RedirectToAction(IndexAction, GalleryControllerConst, new { area = AreaGallery })); }
public async Task <IActionResult> Delete(int id) { bool isSupplementExistingById = await this.supplementService.IsSupplementExistingById(id, false); if (!isSupplementExistingById) { TempData.AddErrorMessage(string.Format(EntityNotFound, SupplementEntity)); return(this.RedirectToSupplementsIndex(false)); } await this.managerSupplementService.DeleteAsync(id); TempData.AddSuccessMessage(string.Format(EntityDeleted, SupplementEntity)); return(this.RedirectToSupplementsIndex(false)); }
public async Task <IActionResult> Edit(int id) { bool isCategoryExistingById = await this.categoryService.IsCategoryExistingById(id, false); if (!isCategoryExistingById) { TempData.AddErrorMessage(string.Format(EntityNotFound, CategoryEntity)); return(this.RedirectToCategoriesIndex(false)); } CategoryBasicServiceModel category = await this.managerCategoryService.GetEditModelAsync(id); CategoryFormViewModel model = Mapper.Map <CategoryFormViewModel>(category); return(View(model)); }
public async Task <IActionResult> Restore(int id) { bool isCategoryExistingById = await this.categoryService.IsCategoryExistingById(id, true); if (!isCategoryExistingById) { TempData.AddErrorMessage(string.Format(EntityNotFound, CategoryEntity)); return(this.RedirectToCategoriesIndex(true)); } await this.managerCategoryService.RestoreAsync(id); TempData.AddSuccessMessage(string.Format(EntityRestored, CategoryEntity)); return(this.RedirectToCategoriesIndex(true)); }
public IActionResult UpdateStatus(AdminUpdateOrderStatusFormModel model) { var order = this._orders.Details(model.OrderId); if (order == null) { TempData.AddErrorMessage("Няма поръчка с Id: " + model.OrderId); return(RedirectToAction(nameof(ListAll))); } this._orders.UpdateStatus(order.Id, model.StatusId); TempData.AddSuccessMessage("Успешно обновихте статуса на проръчката."); return(RedirectToAction("Index", "Home", new { area = "" })); }
public async Task <IActionResult> Create(int id, ReviewFormViewModel model) { if (!ModelState.IsValid) { model.Ratings = this.GetRatingsSelectListItems(); ViewData["SupplementId"] = id; return(View(model)); } bool isSupplementExisting = await this.supplementService.IsSupplementExistingById(id, false); if (!isSupplementExisting) { TempData.AddErrorMessage(string.Format(EntityNotFound, SupplementEntity)); return(this.RedirectToHomeIndex()); } string username = User.Identity.Name; bool isUserRestricted = await this.userService.IsUserRestricted(username); if (isUserRestricted) { TempData.AddErrorMessage(UserRestrictedErrorMessage); return(this.RedirectToHomeIndex()); } string userId = this.userManager.GetUserId(User); await this.reviewService.CreateAsync(model.Content, model.Rating, userId, id); TempData.AddSuccessMessage(string.Format(EntityCreated, ReviewEntity)); bool isUserModerator = User.IsInRole(ModeratorRole); if (isUserModerator) { return(RedirectToAction(nameof(ReviewsController.Index), Reviews, new { area = ModeratorArea })); } return(this.RedirectToAction(nameof(Index))); }
public async Task <IActionResult> Create(MonthlyConsumablesBindingModel model) { if (!ModelState.IsValid) { TempData.AddErrorMessage(WrongInput); return(this.View(model)); } var isCreated = await this.consumables.CreateAsync(model); if (!isCreated) { return(this.BadRequest()); } TempData.AddSuccessMessage("Успешно въведохте консумативи "); return(RedirectToAction("Index")); }
public override async Task <IActionResult> Delete(int id) { Journey journey = await journeyService.GetByIdAsync(id); if (journey == null) { TempData.AddErrorMessage(WebConstants.ErrorTryAgain); return(NotFound()); } foreach (UserJourney passenger in journey.Passengers) { this.SendEmailToPassenger(journey, passenger.User.Email, EmailConstants.RemoveSubject, EmailConstants.RemoveBody); } return(await base.Delete(id)); }
public IActionResult Edit(int id, EditRoomServiceModel room) { if (!ModelState.IsValid) { TempData.AddErrorMessage(ErrorModelState()); return(View(room)); } if (!User.IsInRole(AdminRole)) { return(RedirectToAction(HomeIndex)); } this.rooms.Edit( room); TempData.AddSuccessMessage(SuccessfullEditedRoom(room.Name)); return(RedirectToAction(IndexAction, HomeControllerConst, new { area = AdminArea })); }
public async Task <IActionResult> Edit(int id) { bool isManufacturerExistingById = await this.manufacturerService.IsManufacturerExistingById(id, false); if (!isManufacturerExistingById) { TempData.AddErrorMessage(string.Format(EntityNotFound, ManufacturerEntity)); return(this.RedirectToManufacturersIndex(false)); } ManufacturerBasicServiceModel manufacturer = await this.managerManufacturerService.GetEditModelAsync(id); ManufacturerFormViewModel model = Mapper.Map <ManufacturerFormViewModel>(manufacturer); return(View(model)); }
public async Task <IActionResult> Restore(int id) { bool isManufacturerExistingById = await this.manufacturerService.IsManufacturerExistingById(id, true); if (!isManufacturerExistingById) { TempData.AddErrorMessage(string.Format(EntityNotFound, ManufacturerEntity)); return(this.RedirectToManufacturersIndex(true)); } await this.managerManufacturerService.RestoreAsync(id); TempData.AddSuccessMessage(string.Format(EntityRestored, ManufacturerEntity)); return(this.RedirectToManufacturersIndex(true)); }
public async Task <IActionResult> BookDoctor(PatientAppointmentFormViewModel model) { if (User.IsInRole(WebConstants.DoctorRole)) { TempData.AddErrorMessage("You are logged as Doctor! If oyu want to book an appointment you have to login/register as Patient!"); return(RedirectToAction("Schedule", "Doctors", new { area = "Doctors" })); } if (!ModelState.IsValid) { var doctorsListItems = await GetDoctorsListItemsAsync(); model.Doctors = doctorsListItems; return(View(model)); } var isAvailable = await CheckAvailabilityAsync( model.DoctorId, model.Date, model.TimeStart); if (!isAvailable) { var doctorsListItems = await GetDoctorsListItemsAsync(); model.Doctors = doctorsListItems; return(View(model)); } var currentUser = await this.userManager.GetUserAsync(HttpContext.User); await this.bookingService .AddAsync(model.Info, model.Date.Date, model.TimeStart, model.TimeEnd, model.DoctorId, currentUser.Id); TempData.AddSuccessMessage("You just made a booking! Please do not forget your appointment!"); return(RedirectToAction(nameof(Appointments))); }
public async Task <IActionResult> Edit(string id, UserAdminEditViewModel model) { if (!ModelState.IsValid) { model.AllRoles = await this.roleManager.Roles.Select(r => r.Name).ToListAsync(); return(View(model)); } var exists = await this.users.ExistsAsync(id); if (!exists) { return(BadRequest()); } foreach (var role in model.Roles) { if (!await roleManager.RoleExistsAsync(role)) { return(BadRequest()); } } var usernameAlreadyTaken = await this.users.AlreadyExistsAsync(id, model.Email); if (usernameAlreadyTaken) { TempData.AddErrorMessage(UserErrorConstants.UserAlreadyExists); model.AllRoles = await this.roleManager.Roles.Select(r => r.Name).ToListAsync(); return(View(model)); } string profilePictureUrl = model.NewProfilePicture != null ? await this.fileService.UploadImageAndGetUrlAsync( model.NewProfilePicture, UserDataConstants.ProfilePictureWidth, UserDataConstants.ProfilePictureHeight) : null; string profilePictureNavUrl = model.NewProfilePicture != null ? await this.fileService.UploadImageAndGetUrlAsync( model.NewProfilePicture, UserDataConstants.ProfilePictureNavWidth, UserDataConstants.ProfilePictureNavHeight) : null; await this.users.EditAsync(id, model.FirstName, model.LastName, model.Email, model.Email, model.Roles, profilePictureUrl, profilePictureNavUrl); TempData.AddSuccessMessage(UserSuccessMessages.EditMessage); return(RedirectToAction(nameof(All))); }
public IActionResult ModifyCountry(int[] idCountries) { if (idCountries.Length == 0 || idCountries.Length >= 2) { TempData.AddErrorMessage(WebConstants.MultipleCountriesSelection); return(RedirectToAction(nameof(Index))); } var country = this.country.ById(idCountries[0]); return(View(new AddCountryViewModel { IdCountry = idCountries[0], Country = country.Country, RefSite = country.RefSite, SpphIdCountry = country.SpphIdCountry })); }