public async Task DeleteByIdAsync_WithCorrectData_ShouldSuccessfullyDelete() { var testName = "TestName"; // Arrange var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var categoryRepository = new EfDeletableEntityRepository <Category>(context); var categoriesService = new CategoriesService(categoryRepository); var inputModel = new CreateCategoryInputModel() { Name = testName, }; await categoriesService.CreateAsync(inputModel); var category = categoryRepository.All().FirstOrDefault(c => c.Name == testName); // Act var expectedCateogiesCount = 0; await categoriesService.DeleteByIdAsync(category.Id); var actualCategoriesCount = categoryRepository.All().Count(); // Assert Assert.Equal(expectedCateogiesCount, actualCategoriesCount); }
public async Task EditAsync_WithCorrectData_ShouldSuccessfullyEdit() { var testName = "TestName"; // Arrange var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var categoryRepository = new EfDeletableEntityRepository <Category>(context); var categoriesService = new CategoriesService(categoryRepository); var inputModel = new CreateCategoryInputModel() { Name = testName, }; await categoriesService.CreateAsync(inputModel); var category = categoryRepository.All().FirstOrDefault(c => c.Name == testName); // Act var expectedCategoryName = "Edited_TestName"; var editInputModel = new CategoryInfoViewModel() { Id = category.Id, Name = expectedCategoryName, }; await categoriesService.EditAsync(editInputModel); var actualCategoryName = category.Name; // Assert category = await categoryRepository.GetByIdWithDeletedAsync(category.Id); Assert.Equal(expectedCategoryName, actualCategoryName); }
public async Task GetIdByName_WithCorrectData_ShouldReturnId() { var testName = "TestName"; // Arrange var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var categoryRepository = new EfDeletableEntityRepository <Category>(context); var categoriesService = new CategoriesService(categoryRepository); var inputModel = new CreateCategoryInputModel() { Name = testName, }; await categoriesService.CreateAsync(inputModel); var category = categoryRepository.All().FirstOrDefault(c => c.Name == testName); // Act var expectedCategoryId = category.Id; var actualCategoryId = categoriesService.GetIdByName(testName); // Assert Assert.Equal(expectedCategoryId, actualCategoryId); }
public async Task GetCategoryById_WithCorrectData_ShouldReturnCorrectResult() { var testName = "CategoryTestName"; // Arrange var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var categoryRepository = new EfDeletableEntityRepository <Category>(context); var categoriesService = new CategoriesService(categoryRepository); var inputModel = new CreateCategoryInputModel() { Name = testName, }; await categoriesService.CreateAsync(inputModel); var category = categoryRepository.All().FirstOrDefault(x => x.Name == testName); // Act var expectedCategoryId = category.Id; var expectedReturnType = typeof(CategoryInfoViewModel); var actualReturnType = categoriesService.GetCategoryByName(testName).GetType(); var actualCategoryId = categoriesService.GetCategoryByName(testName).Id; // Assert Assert.True(expectedReturnType == actualReturnType); Assert.Equal(expectedCategoryId, actualCategoryId); }
public ActionResult Create(CreateCategoryInputModel model) { if (!ModelState.IsValid) { return(View(model)); } var category = new Category { Name = HttpUtility.HtmlEncode(model.Name) }; if (categoryService.Exist(category.Name)) { TempData["error"] = ErrorMessages.CategoryAlreadyExist; return(View()); } categoryService.SaveItem(category); TempData["success"] = SuccessMessages.CategoryCreatedSuccess; return(RedirectToAction("All")); }
public async Task <IActionResult> Create(CreateCategoryInputModel model) { if (!this.ModelState.IsValid || (model.PictureUrl == null && model.Image == null)) { if (string.IsNullOrWhiteSpace(model.PictureUrl) && model.Image == null) { this.ModelState.AddModelError("PictureUrl", "Picture Url is required."); } return(this.View()); } if (model.Image != null) { var pictureUrl = await this.cloudinary.ImageUploadAsync(model.Image); model.PictureUrl = pictureUrl; } var user = await this.userManager.GetUserAsync(this.User); await this.categoriesService.CreateAsync(model.Name, model.PictureUrl, user.Id); return(this.RedirectToAction(nameof(this.All))); }
public IActionResult Edit(CreateCategoryInputModel viewModel) { var category = this.categoryService.GetCategoryById(viewModel.Id); this.categoryService.EditCategory(viewModel.Name, viewModel.Id); return(this.RedirectToAction("CategoryList")); }
public IActionResult Create(CreateCategoryInputModel model) { var cat = mapper.Map <Category>(model); context.Categories.Add(cat); context.SaveChanges(); return(RedirectToAction("All", "Categories")); }
public CreateCategoryInputModel GetCategoryById(string id) { var result = this.context.Categories.FirstOrDefault(x => x.Id == id); var res = new CreateCategoryInputModel { Name = result.Name }; return(res); }
public async Task <IActionResult> Create(CreateCategoryInputModel model) { var newCategory = Mapper.Map <Category>(model); await this.categories.AddAsync(newCategory); await this.categories.SaveChangesAsync(); return(this.RedirectToAction(nameof(Index))); }
public async Task <int> CreateCategory(CreateCategoryInputModel inputModel) { var destination = this.mapper.Map <Category>(inputModel); await this.categoriesRepository.AddAsync(destination); var statusCode = await this.categoriesRepository.SaveChangesAsync(); return(statusCode); }
public IActionResult Create(CreateCategoryInputModel model) { var category = new Category { Name = model.CategoryName }; this.context.Categories.Add(category); this.context.SaveChanges(); return(this.RedirectToAction("All")); }
public async Task <IActionResult> Create(CreateCategoryInputModel input) { if (!this.ModelState.IsValid) { return(this.View(input)); } await this.categoriesService.CreateAsync(input.Name, input.Description, input.ImageUrl); return(this.Redirect("/")); }
public async Task CreateAsync(CreateCategoryInputModel input) { var category = new CategoryProduct { Name = input.Name, }; await this.categoriesRepository.AddAsync(category); await this.categoriesRepository.SaveChangesAsync(); }
public async Task <IActionResult> AddAsync(CreateCategoryInputModel input) { if (!this.ModelState.IsValid) { return(this.View()); } await this.categoriesService.AddAsync(input); return(this.Redirect("/")); }
public async Task <IActionResult> Create(CreateCategoryInputModel input) { if (!this.ModelState.IsValid) { return(this.View(input)); } await this.categoryService.CreateAsync(input); return(this.RedirectToAction(nameof(this.Index))); }
public CategoryStartUp() { var config = new MapperConfiguration(cfg => cfg.AddProfile <FastFoodProfile>()); _context = new FastFoodContext(); _mapper = new Mapper(config); _viewModel = new CreateCategoryInputModel { CategoryName = "Watches" }; }
public async Task <IActionResult> AddCategory(CreateCategoryInputModel input) { if (!this.ModelState.IsValid) { return(this.View(input)); } //May use the id for something later. var id = await this.categoriesService.Create(input.Name); TempData["message"] = $"{input.Name} has been saved"; return(RedirectToAction("Index")); }
public async Task CreateAsync(CreateCategoryInputModel input) { var category = new Category() { Name = input.Name, PictureUrl = input.PictureUrl, }; await this.categoryRepository.AddAsync(category); await this.categoryRepository.SaveChangesAsync(); }
public IActionResult Create(CreateCategoryInputModel model) { if (!ModelState.IsValid) { return(RedirectToAction("Error", "Home")); } Category newCategory = mapper.Map <Category>(model); context.Categories.Add(newCategory); context.SaveChanges(); return(RedirectToAction("All", "Categories")); }
public IActionResult Delete(string id) { var category = this.categoryService.GetCategoryById(id); var model = new CreateCategoryInputModel { Id = category.Id, Name = category.Name, }; return(this.View(model)); }
public IActionResult Create(CreateCategoryInputModel model) { if (!this.ModelState.IsValid) { return(this.RedirectToAction("Error", "Home")); } var category = this.mapper.Map <Category>(model); this.context.Categories.Add(category); this.context.SaveChanges(); return(this.RedirectToAction("All", "Categories")); }
public IActionResult Create(CreateCategoryInputModel model) { if (!ModelState.IsValid) { return(RedirectToAction("Error", "Create")); } CreateCategoryDto categoryDto = this.mapper.Map <CreateCategoryDto>(model); this.categoryService.Create(categoryDto); return(RedirectToAction("All")); }
public async Task <IActionResult> Create(CreateCategoryInputModel input) { if (this.User.IsInRole("Administrator")) { if (!this.ModelState.IsValid) { return(this.View(input)); } await this.categoriesService.Create(input.Name, input.Image); } return(this.RedirectToAction("Index", "Categories")); }
public async Task <bool> CreateAsync(CreateCategoryInputModel model) { var category = new NutriAnimal.Data.Models.Category { Name = model.Name, }; await this.context.Categories.AddAsync(category); int result = await this.context.SaveChangesAsync(); return(result > 0); }
public async Task <IActionResult> Create(CreateCategoryInputModel input) { if (!this.ModelState.IsValid) { return(this.View(input)); } string pictureUrl = await this.cloudinaryService.UploadPictureAsync( input.ImageUrl, input.Name); await this.categoryService.CreateAsync(input.Name, pictureUrl); return(this.RedirectToAction("All", "Categories", new { area = string.Empty })); }
public async Task <IActionResult> Create(CreateCategoryInputModel inputModel) { if (!ModelState.IsValid) { return(this.View(inputModel)); } var categoryId = await this.categoryService.Create(inputModel.Name, inputModel.Title, inputModel.Description, inputModel.ImageUrl); if (string.IsNullOrEmpty(categoryId)) { return(this.Redirect("/")); } return(RedirectToAction(nameof(All))); }
public async Task <IActionResult> Create(CreateCategoryInputModel inputModel) { if (!ModelState.IsValid) { return(this.View(inputModel)); } var result = await this.categoryService.Create(inputModel.Name); if (!result) { return(this.Redirect("/")); } return(RedirectToAction(nameof(All))); }
public IActionResult Create(CreateCategoryInputModel model) { if (!ModelState.IsValid) { return(RedirectToAction("Error", "Home")); } var category = this.mapper.Map <Category>(model); this.context.Categories.Add(category); this.context.SaveChanges(); return(RedirectToAction("All")); throw new NotImplementedException(); }
public IActionResult Create(CreateCategoryInputModel model) { if (!this.ModelState.IsValid) { return(this.RedirectToAction("Error", "Home")); } var categoryServiceModel = new CreateCategoryServiceModel() { Name = model.Name, Description = model.Description }; this.categoryService.Create(categoryServiceModel); return(this.RedirectToAction("All", "Categories")); }