public IActionResult EditCategory([Bind(nameof(EditCategoryModel.Id), nameof(EditCategoryModel.Name))] EditCategoryModel model) { if (ModelState.IsValid) { try { model.Edit(); model.Response = new ResponseModel("Category editing successful.", ResponseType.Success); //logger code _logger.LogInformation("Category Edit Successful"); return(RedirectToAction("Index")); } catch (DuplicationException ex) { model.Response = new ResponseModel(ex.Message, ResponseType.Failure); // error logger code _logger.LogError($"Category Name Already Exist so Edit 'Failed'. Excption is : {ex.Message}"); } catch (Exception ex) { model.Response = new ResponseModel("Category Edit Failued.", ResponseType.Failure); // error logger code _logger.LogError($"Category Edit 'Failed'. Excption is : {ex.Message}"); } } return(View(model)); }
public ActionResult EditCategory(EditCategoryModel model) { if (ModelState.IsValid) { if (_categoryRepository.ExistTitleCategory(model.Title, model.Id)) { ModelState.AddModelError("Title", "Данная категория уже есть в БД"); return View("EditCategory", model); } var category = _categoryRepository.GetCategotyById(model.Id) ?? new Category(); category = Mapper.Map(model, category); if (_categoryRepository.ExistCategory(model.Id)) { category.ModificationDate = DateTime.Now; _categoryRepository.EditCategory(category); } else { category.CreationDate = DateTime.Now; category.ModificationDate = DateTime.Now; _categoryRepository.AddCategory(category); } return RedirectToAction("Index"); } return View("EditCategory", model); }
public async Task <IActionResult> EditCategory(int id) { var model = new EditCategoryModel(); await model.LoadByIdAsync(id); return(View(model)); }
public ActionResult Edit(EditCategoryModel vm) { try { //Check data validation if (!ModelState.IsValid) { this.AddToastMessage(Messages.InvalidValueField, ToastType.Error); return(View("Edit", vm)); } //Update Category _categoryService.Update(vm); //Successfully message this.AddToastMessage(string.Format(Messages.RecordSavedSuccessfully, "category"), ToastType.Success); return(RedirectToAction("Index")); } catch (CustomException ex) { this.AddToastMessage(ex.Message, ToastType.Error); return(View("Edit", vm)); } catch (Exception ex) { this.AddToastMessage(Messages.GeneralError, ToastType.Error); return(View("Edit", vm)); } }
ActionOutput ICategoryManager.ModifyCategory(EditCategoryModel model) { ActionOutput res = new ActionOutput(); try { var exists = Context.Categories.Where(p => p.Id == model.id).FirstOrDefault(); if (exists != null) { var already = Context.Categories.Where(p => p.Name == model.Name && p.Id != model.id).Any(); if (!already) { exists.Description = model.Description; exists.Name = model.Name; Context.SaveChanges(); return(SuccessResponse("Category updated Successfully")); } else { return(ErrorResponse("Category already exists with Same Name")); } } else { return(ErrorResponse("Category doesn't exists")); } } catch (Exception ex) { return(ErrorResponse("Category doesn't exists")); } }
public async Task <IActionResult> EditCategory( [Bind(nameof(EditCategoryModel.Id), nameof(EditCategoryModel.Name), nameof(EditCategoryModel.PostCount))] EditCategoryModel model) { if (ModelState.IsValid) { try { await model.UpdateAsync(); model.Response = new ResponseModel("Category editing successful.", ResponseType.Success); return(RedirectToAction("Index")); } catch (DuplicationException ex) { model.Response = new ResponseModel(ex.Message, ResponseType.Failure); _logger.LogInformation(ex.Message); } catch (Exception ex) { model.Response = new ResponseModel("Category editing failed.", ResponseType.Failure); _logger.LogInformation(ex.Message); } } return(View(model)); }
public virtual async Task <IActionResult> Edit(EditCategoryModel model) { var serviceResult = await service.UpdateCategoryAsync(model.Id, model.Name, model.CategoryImage?.FileName); if (serviceResult.Success) { //Prepare instances string oldImageUrl = serviceResult.Result.oldImageUrl; var category = serviceResult.Result.updatedCategory; //If category image is not null, new image is uploded await model.CategoryImage?.UpdateImageAsync(environment.GetFullCategoryPath(), category.Name, oldImageUrl); //Prepare success message ViewBag.Message = "Category successfuly updated"; //Prepare EditCategoryModel instance var categoryModel = mapper.Map <EditCategoryModel>(category); categoryModel.GetPaths(IHostingExtension.CategoryFolderDisplay); return(View(categoryModel)); } //Display errors ModelState.FillWithErrors(serviceResult.Errors); return(View(model)); }
public async Task <ActionResult> _Edit(EditCategoryModel model) { var nameResponse = await WepApiMethod.SendApiAsync <bool>(HttpVerbs.Get, $"KMC/Category/IsNameExist?id={model.Id}&title={model.Title}"); if (nameResponse.isSuccess) { TempData["ErrorMessage"] = Language.KMCCategory.ValidExistName; return(RedirectToAction("List")); } if (ModelState.IsValid) { var response = await WepApiMethod.SendApiAsync <bool>(HttpVerbs.Put, $"KMC/Category?id={model.Id}", model); if (response.isSuccess) { TempData["SuccessMessage"] = Language.KMCCategory.AlertSuccessUpdate; await LogActivity(Modules.KMC, "Update KMC Category", model); return(RedirectToAction("List")); } } TempData["ErrorMessage"] = Language.KMCCategory.AlertFailUpdate; return(RedirectToAction("List")); }
public async Task <IActionResult> Edit(EditCategoryModel model) { var response = await _categoryService.EditAsync(model); if (response.Success) { return(Ok()); } var errorMessage = ""; switch (response.ErrorType) { case ErrorType.EntityNotFound: errorMessage = "Kategori bulunamadı"; break; case ErrorType.DuplicatedCategoryName: errorMessage = "Bu kategori adı daha önce kullanılmıştır."; break; default: errorMessage = "Kategori düzenlenemedi."; break; } return(BadRequest(new { errorMessage })); }
public async Task <ServiceResponse> EditAsync(EditCategoryModel model) { if (model == null) { return(new ServiceResponse(false, ErrorType.NullModel)); } var entity = await _unitOfWork.CategoryRepository.FindOneAsync(x => x.Id == model.Id); if (entity == null) { return(new ServiceResponse(false, ErrorType.EntityNotFound)); } if (entity.Name != model.Name) { if (await _unitOfWork.CategoryRepository.FindOneAsync(x => x.Name == model.Name) != null) { return(new ServiceResponse(false, ErrorType.DuplicatedCategoryName)); } } entity.Name = model.Name; entity.Slug = model.Name.ConvertToSlugFormat(); if (model.ImageFile != null) { var suffix = Guid.NewGuid().ToString(); await _imageService.SaveCategoryImage(model.ImageFile, suffix, entity.ImageName); entity.ImageName = Path.GetFileNameWithoutExtension(model.ImageFile.FileName) + "-" + suffix + Path.GetExtension(model.ImageFile.FileName); } await _unitOfWork.CategoryRepository.UpdateAsync(entity); return(new ServiceResponse(true)); }
public IActionResult EditCategory(int id) { var model = new EditCategoryModel(); model.Load(id); return(View(model)); }
public IActionResult Edit(EditCategoryModel categoryParams) { var categoryData = _mapper.Map <CategoryDTO>(categoryParams); _categoryService.Edit(categoryData); return(Json("OK")); }
public ActionResult AddCategory() { var model = new EditCategoryModel { PageTitle = "Добавление новой категории", }; return View("EditCategory", model); }
public HttpResponseMessage EditCategory(EditCategoryModel model) { using (MobileStoreServiceEntities data = new MobileStoreServiceEntities()) { CATEGORY c = data.CATEGORies.FirstOrDefault(cat => cat.CATEGORY_ID == model.ID); c.CATEGORY_NAME = model.Name; data.SaveChanges(); } return(CreateResponse(HttpStatusCode.OK)); }
public ActionResult _Edit(int id, string No, string Title) { var model = new EditCategoryModel { Id = id, No = No, Title = Title }; return(View(model)); }
public ActionResult <string> EditCategory(EditCategoryModel model) { try { _repository.EditCategory(LoggedUser, model.OldCategory.Sanitize(), model.NewCategory.Sanitize()); return("SUCCESS"); } catch (Exception ex) { return(ex.Message); } }
public IHttpActionResult PutCategory(EditCategoryModel model) { if (ModelState.IsValid) { try { var categoryService = new CategoryService(); var category = categoryService.GetCategoryById(new GetCategoryByIdRequest() { Id = model.Id }).Category; if (category == null) { return(NotFound()); } if (model.IdUpperCategory.HasValue) { // Controla que exista la categoría padre. var upperCategory = categoryService.GetCategoryById(new GetCategoryByIdRequest() { Id = model.IdUpperCategory.Value }).Category; if ((upperCategory == null) || (model.Id == model.IdUpperCategory)) { return(BadRequest("Invalid upper category")); } } var request = new UpdateCategoryRequest { Id = model.Id, Title = model.Title, Summary = model.Summary, Description = model.Description, IdUpperCategory = model.IdUpperCategory }; var result = categoryService.UpdateCategory(request); return(Ok()); } catch (Exception) { return(BadRequest()); } } else { return(BadRequest(ModelState)); } }
public ActionResult Edit(EditCategoryModel model, string returnUrl) { if (ModelState.IsValid) { var cat = db.Categories.Find(model.Id); cat.Name = model.Name; cat.Description = model.Description; db.SaveChanges(); return(returnUrl == null?RedirectToAction("Details", "Households") : RedirectToLocal(returnUrl, RedirectToAction("Details", "Households"))); } return(returnUrl == null?RedirectToAction("Details", "Households") : RedirectToLocal(returnUrl, RedirectToAction("Details", "Households"))); }
public async Task EditCategory(EditCategoryModel model) { var category = await this.GetByIdAsync(model.CategoryId); category.Title = model.CategoryTitle; category.Description = new HtmlSanitizer().Sanitize(model.CategoryDescription); if (model.ImageUrl != null) { category.ImageUrl = model.ImageUrl; } this.categoriesRepository.Update(category); await this.categoriesRepository.SaveChangesAsync(); }
public async Task EditCategory(EditCategoryModel viewModel) { var category = await _dbContext.Categories .Where(c => c.Id == Guid.Parse(viewModel.Id)) .FirstOrDefaultAsync(); if (category == null) { throw new ArgumentException("Category does not exists"); } category.Name = viewModel.Name; await _dbContext.SaveChangesAsync(); }
public async Task <IActionResult> EditCategory(string id) { var category = await this.categoryService.GetCategoryByIdAsync(id); var output = new EditCategoryModel { CategoryViewModel = new CategoryViewModel { Id = category.Id, Name = category.Name, ImgPath = category.ImgPath, }, }; return(this.View(output)); }
public async Task <IActionResult> Edit(EditCategoryModel model) { if (!await this.DoesItExist(model.CategoryId)) { return(this.NotFound()); } if (model.NewImage != null) { model.ImageUrl = await this.Upload(model.NewImage); } await this.categoryService.EditCategory(model); return(this.RedirectToAction("Index", "Category")); }
public IActionResult Edit(int?id, [FromBody] EditCategoryModel editCategoryModel) { if (id.HasValue && this.categoryService.CategoryExists(id.Value)) { if (this.ModelState.IsValid) { var result = this.categoryService.Edit(id.Value, editCategoryModel.Name); return(Ok(result)); } return(BadRequest(this.ModelState)); } return(NotFound(InvalidCategoryRequestError)); }
public async Task EditCategoryIgnoresNullImageUrlAndKeepsTheOldOne() { await this.SeedDatabase(); var model = new EditCategoryModel { CategoryId = this.testCategory1.Id, CategoryTitle = "Warframe", CategoryDescription = "A category for the popular game warframe created by DE", ImageUrl = null, }; await this.service.EditCategory(model); Assert.NotNull(this.testCategory1.ImageUrl); }
public async Task <IActionResult> OnGetAsync(string id) { if (id == null) { return(NotFound()); } var category = await _videoService.GetCategory(id); Model = new EditCategoryModel { Id = category.Id, Name = category.Name }; return(Page()); }
public async Task EditCategoryChangesAllTheNeededProperties() { await this.SeedDatabase(); var model = new EditCategoryModel { CategoryId = this.testCategory1.Id, CategoryTitle = "Warframe", CategoryDescription = "A category for the popular game warframe created by DE", ImageUrl = "test123.png", }; await this.service.EditCategory(model); Assert.Equal(model.CategoryTitle, this.testCategory1.Title); Assert.Equal(model.CategoryDescription, this.testCategory1.Description); Assert.Equal(model.ImageUrl, this.testCategory1.ImageUrl); }
public virtual async Task <IActionResult> EditAjax(EditCategoryModel model) { var serviceResult = await service.UpdateCategoryAsync(model.Id, model.Name, model.CategoryImage?.FileName); if (serviceResult.Success) { //Prepare instances string oldImageUrl = serviceResult.Result.oldImageUrl; var category = serviceResult.Result.updatedCategory; //If category image is not null, new image is uploded await model.CategoryImage?.UpdateImageAsync(environment.GetFullCategoryPath(), category.Url, oldImageUrl); return(Json(new { success = true, redirectAction = nameof(Index) })); } return(Json(new { success = false, message = serviceResult.Errors[0] })); }
public async Task <IActionResult> Edit(int id, EditCategoryModel category) { var dbCategory = await this.categories.GetSingleOrDefaultAsync(x => x.Name == category.Name); if (dbCategory == null) { return(NotFound()); } if (this.ModelState.IsValid) { dbCategory.Name = category.Name; this.categories.Update(dbCategory); return(RedirectToAction(nameof(Index))); } return(View(category)); }
public async Task <IActionResult> Put(int id, [FromBody] EditCategoryModel model) { var existsCategory = await this.categoriesService.ExistsCategoryWithIdAsync(id); if (!existsCategory) { return(this.NotFound()); } var existingName = await this.categoriesService.ExistsCategoryWithNameAsync(model.Name); if (existingName) { return(this.BadRequest($"Category with name: \"{model.Name}\" exists already.")); } await this.categoriesService.EditAsync(id, model.Name); return(this.Ok()); }
public IHttpActionResult Put(int id, [FromBody] EditCategoryModel model) { var category = db.KMCCategory.Where(s => s.Id == id).FirstOrDefault(); if (category != null) { category.Title = model.Title; db.Entry(category).State = EntityState.Modified; db.Entry(category).Property(x => x.Display).IsModified = false; db.SaveChanges(); return(Ok(true)); } else { return(NotFound()); } }
public async Task <IActionResult> Create(EditCategoryModel category) { var dbCategory = await this.categories.GetSingleOrDefaultAsync(x => x.Name == category.Name); if (dbCategory != null) { Danger(WebConstants.SuchCategoryExists); return(RedirectToAction(nameof(Create))); } if (this.ModelState.IsValid) { var categoryToAdd = new Category() { Name = category.Name }; this.categories.Add(categoryToAdd); Success(string.Format(WebConstants.CategoryCreated, category.Name)); return(RedirectToAction(nameof(Index))); } return(View(category)); }
public async Task <IActionResult> EditCategory(string id, EditCategoryModel input) { await this.categoryService.EditCategoryByIdAsync(id, input.CategoryInputModel); return(this.RedirectToAction("AllCategoriesAndSubCategories")); }