コード例 #1
0
        public IActionResult Edit(int id)
        {
            var model = new CategoryUpdateModel();

            model.Load(id);
            return(View(model));
        }
コード例 #2
0
        public async Task <CategoryUpdateModel> Update(CategoryUpdateModel model)
        {
            if (!_isAuthorized)
            {
                throw _eNotFound <CategoryUpdateModel>("Category not found");
            }

            Category entity = null;

            if (string.IsNullOrWhiteSpace(model.Id))
            {
                entity = _mapper.Map <Category>(model);
            }
            else
            {
                entity = (await _repositoryCategory.GetFirst(x => x.Id == model.Id && x.State == MRApiCommon.Infrastructure.Enum.MREntityState.Active)
                          ?? throw _eNotFound <CategoryUpdateModel>("Category not found"));
                entity = _mapper.Map(model, entity);
            }

            entity = string.IsNullOrWhiteSpace(entity.Id)
                ? await _repositoryCategory.Insert(entity)
                : await _repositoryCategory.Replace(entity);

            return(_mapper.Map <CategoryUpdateModel>(entity));
        }
コード例 #3
0
        protected void CheckUpdateModel(CategoryUpdateModel model)
        {
            if (model == null)
            {
                throw new ModelDamagedException(nameof(model), "is required");
            }

            if (string.IsNullOrWhiteSpace(model.Slug))
            {
                throw new ModelDamagedException(nameof(model.Slug), "is required");
            }

            if (model.Translations == null || !model.Translations.Any())
            {
                throw new ModelDamagedException(nameof(model.Translations), "is required");
            }

            if (model.Translations.Count(x => x.IsDefault) != 1)
            {
                throw new ModelDamagedException(nameof(model.Translations), "one must be default");
            }

            var damagedTranslation = model.Translations.FirstOrDefault(x => string.IsNullOrWhiteSpace(x.Name) || string.IsNullOrWhiteSpace(x.LanguageCode));

            if (damagedTranslation != null)
            {
                throw new ModelDamagedException(nameof(model.Translations), "damaged");
            }

            if (model.Translations.GroupBy(x => x.LanguageCode).Any(x => x.Count() > 1))
            {
                throw new ModelDamagedException(nameof(model.Translations), "one must be default");
            }
        }
コード例 #4
0
        public IActionResult Delete(int id)
        {
            var model = new CategoryUpdateModel();

            model.Delete(id);
            return(RedirectToAction("Index"));
        }
コード例 #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="cat"></param>
        /// <returns></returns>
        public string UpdateCategoryDetail(CategoryUpdateModel cat)
        {
            Category catToUpdate = new Category();
            string   result;

            if (cat == null)
            {
                result = "Input is null.";
                return(result);
            }
            else if (string.IsNullOrEmpty(cat.CategoryName))
            {
                result = "Category Name should not be blank.";
                return(result);
            }
            else
            {
                catToUpdate.Id             = cat.Id;
                catToUpdate.CategoryName   = cat.CategoryName;
                catToUpdate.IsActive       = true;
                catToUpdate.UpdateUserName = "******";
                catToUpdate.UpdateDttm     = DateTime.UtcNow;

                result = _CategoryDataAccess.UpdateCategoryDetails(catToUpdate);

                return(result);
            }
        }
コード例 #6
0
 public IActionResult Edit(CategoryUpdateModel model)
 {
     if (ModelState.IsValid)
     {
         model.EditCaregory();
     }
     return(View(model));
 }
コード例 #7
0
        public async Task <Category> InsertAsync(CategoryUpdateModel Category)
        {
            var result = await this.Context.AddAsync(this.Mapper.Map <Category>(Category));

            await this.Context.SaveChangesAsync();

            return(this.Mapper.Map <Category>(result.Entity));
        }
コード例 #8
0
 public ActionResult Add(CategoryUpdateModel model)
 {
     if (ModelState.IsValid)
     {
         model.AddNewCategory();
     }
     return(View(model));
 }
コード例 #9
0
        public async Task UpdateAsync(CategoryUpdateModel model)
        {
            var jsonData = JsonConvert.SerializeObject(model);
            var content  = new StringContent(jsonData, Encoding.UTF8, "application/json");

            _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", _httpContextAccessor.HttpContext.Session.GetString("token"));
            await _httpClient.PutAsync($"{model.Id}", content);
        }
コード例 #10
0
        public IActionResult ViewCategoryDetails(int id, string error = "")
        {
            CategoryUpdateModel categoryUpdateModel = new CategoryUpdateModel {
                category = _context.Categories.Find(id)
            };

            ViewBag.error = error;
            return(View(categoryUpdateModel));
        }
コード例 #11
0
        public async Task <IActionResult> Update(CategoryUpdateModel model)
        {
            if (ModelState.IsValid)
            {
                await _categoryApiService.UpdateAsync(model);

                return(RedirectToAction("Index"));
            }
            return(View(model));
        }
コード例 #12
0
        public async Task <IActionResult> Update(CategoryUpdateModel categoryUpdateModel)
        {
            TempData["active"] = "category";
            if (ModelState.IsValid)
            {
                await _categoryApiService.UpdateAsync(categoryUpdateModel);

                return(RedirectToAction("Index"));
            }
            return(View(categoryUpdateModel));
        }
コード例 #13
0
        public static CategoryUpdateModel ToCategoryUpdateModel(Category dbModel)
        {
            var updateModel = new CategoryUpdateModel {
                Id          = dbModel.Id,
                Name        = dbModel.Name,
                Description = dbModel.Description,
                OldImageUrl = ToBase64String(dbModel.Image)
            };

            return(updateModel);
        }
コード例 #14
0
        public Guid?Update(CategoryUpdateModel categoryUpdateModel)
        {
            var categoryEntityExisting = categoryRepository.GetById(categoryUpdateModel.Id);

            categoryEntityExisting.Product = productRepository.GetByCategoryId(categoryUpdateModel.Id);
            UpdateCategory(categoryUpdateModel, categoryEntityExisting);

            var categoryEntityUpdated = mapper.Map <CategoryEntity>(categoryUpdateModel);

            return(categoryRepository.Update(categoryEntityUpdated));
        }
コード例 #15
0
        public async Task <IActionResult> Update(int id)
        {
            var result = await _categoryApiService.GetByIdAsync(id);

            CategoryUpdateModel model = new CategoryUpdateModel
            {
                Id   = result.Id,
                Name = result.Name
            };

            return(View(model));
        }
コード例 #16
0
        public void UpdateCategoryDetail_WhenCategoryModelInputIsNull_ReturnsInputIsNullError()
        {
            CategoryUpdateModel input = null;

            Mock <ICategoryDataAccess> mockCategories = new Mock <ICategoryDataAccess>();

            ICategoryBusinessLayer app = new CategoryBusinessLayer(mockCategories.Object);

            var output = app.UpdateCategoryDetail(input);

            Assert.AreEqual("Input is null.", output);
        }
コード例 #17
0
        public ActionResult <CategoryReadModel> Update(int id, CategoryUpdateModel category)
        {
            var filteredCategory = _categoryService.GetById(id);

            if (filteredCategory == null)
            {
                return(NotFound());
            }
            _mapper.Map(category, filteredCategory);
            _categoryService.Update(filteredCategory);
            // _categoryService.SaveChanges();
            return(NoContent());
        }
コード例 #18
0
        public IHttpActionResult UpdateCategory([FromBody] CategoryUpdateModel category)
        {
            var container = ContainerConfig.Configure();

            using (var scope = container.BeginLifetimeScope())
            {
                var app = scope.Resolve <ICategoryBusinessLayer>();

                var result = app.UpdateCategoryDetail(category);

                return(Json(new { Result = result }));
            }
        }
コード例 #19
0
        public async Task CategoryUpdate(CategoryUpdateModel categoryUpdateModel)
        {
            var           jsonData      = JsonConvert.SerializeObject(categoryUpdateModel);
            StringContent stringContent = new StringContent(jsonData, Encoding.UTF8, "application/json");

            _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", _httpContextAccessor.HttpContext.Session.GetString("token"));

            var responseMessage = await _httpClient.PutAsync($"{categoryUpdateModel.Id}", stringContent);

            if (responseMessage.IsSuccessStatusCode)
            {
                //return true;
            }
            //return flase;
        }
コード例 #20
0
        public async Task <IActionResult> UpdateCategory(CategoryUpdateModel categoryUpdateModel)
        {
            var categoryToUpdate = await _categoriesRepository.GetAsync(categoryUpdateModel.Id);

            if (categoryToUpdate == null)
            {
                return(NotFound());
            }

            _mapper.Map(categoryUpdateModel, categoryToUpdate);

            await _categoriesRepository.SaveChangesAsync();

            return(NoContent());
        }
コード例 #21
0
        public async Task <IActionResult> Edit(int id)
        {
            ViewData["Active"] = "category";
            var updatedCategory = await _categoryApiService.GetByIdAsync(id);

            if (updatedCategory != null)
            {
                CategoryUpdateModel categoryUpdateModel = new CategoryUpdateModel
                {
                    Id   = updatedCategory.Id,
                    Name = updatedCategory.Name
                };
                return(View(categoryUpdateModel));
            }
            return(NotFound());
        }
コード例 #22
0
        public static Category ToCategoryDbModel(CategoryUpdateModel updateModel)
        {
            var dbModel = new Category {
                Id          = updateModel.Id,
                Name        = updateModel.Name,
                Description = updateModel.Description,
                Image       = FromFileForm(updateModel.NewImage)
            };

            if (dbModel.Image == null)
            {
                dbModel.Image = FromBase64String(updateModel.OldImageUrl);
            }

            return(dbModel);
        }
コード例 #23
0
        public void UpdateCategoryDetail_WhenCategoryNameIsNullOrEmpty_ReturnsCategoryNameIsBlankError()
        {
            CategoryUpdateModel input = new CategoryUpdateModel()
            {
                CategoryName = string.Empty,
                IsActive     = true
            };

            Mock <ICategoryDataAccess> mockCategories = new Mock <ICategoryDataAccess>();

            ICategoryBusinessLayer app = new CategoryBusinessLayer(mockCategories.Object);

            var output = app.UpdateCategoryDetail(input);

            Assert.AreEqual("Category Name should not be blank.", output);
        }
コード例 #24
0
        public void Update(int id, CategoryUpdateModel category)
        {
            var _category = _typesRepository.Get(id);

            if (_category == null)
            {
                throw new ApplicationException("Błąd, blad edycji");
            }

            _category.Update(category);

            if (!_typesRepository.Update(_category))
            {
                throw new ApplicationException();
            }
        }
コード例 #25
0
        public async Task <IActionResult> update(CategoryUpdateModel category)
        {
            var Item = await _categoryRepo.GetCategory(category.CategoryId);

            if (Item == null)
            {
                return(NotFound());
            }
            var model = new Category {
                CategoryId = category.CategoryId,
                name       = category.name
            };
            await _categoryRepo.update(model);

            return(Ok());
        }
コード例 #26
0
        public async Task <IActionResult> Edit(int id, CategoryUpdateModel categoryUpdateModel)
        {
            TempData["active"] = "category";
            if (id != categoryUpdateModel.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                await _categoryApiService.CategoryUpdate(categoryUpdateModel);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(categoryUpdateModel));
        }
コード例 #27
0
        async public Task <IActionResult> Update(CategoryUpdateModel categoryUpdateModel)
        {
            if (ModelState.IsValid)
            {
                Console.WriteLine("Model valid!");
                var dbModel = DataMapper.ModelMapper.ToCategoryDbModel(categoryUpdateModel);
                _categoryRepository.Update(dbModel);
                await _categoryRepository.SaveChangesAsync();
            }
            else
            {
                Console.WriteLine("Model invalid!");
                return(View("Edit", categoryUpdateModel));
            }

            return(RedirectToAction("Index", "Home"));
        }
コード例 #28
0
        public async Task <IActionResult> Put([FromBody] CategoryUpdateModel categoryUpdateModel)
        {
            CategoryDto categoryDto = await _categoryService.GetCategory(categoryUpdateModel.CategoryId);

            if (categoryDto.Title != categoryUpdateModel.Title)
            {
                if (await _categoryService.Exists(categoryUpdateModel.Title))
                {
                    return(Conflict("This category already exists"));
                }
            }

            CategoryDto categoryUpdateDto  = _mapper.Map <CategoryDto>(categoryUpdateModel);
            CategoryDto updatedCategoryDto = await _categoryService.UpdateCategory(categoryUpdateDto);

            return(CreatedAtAction(nameof(Get), new { id = updatedCategoryDto.CategoryId }, updatedCategoryDto));
        }
コード例 #29
0
        public ActionResult Edit(int id, CategoryUpdateModel updateModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(updateModel));
            }

            try
            {
                _categoryService.Update(id, updateModel);
            }
            catch (Exception e)
            {
                return(new HttpStatusCodeResult(500, e.Message));
            }

            return(RedirectToAction("Index"));
        }
コード例 #30
0
        public void UpdateCategoryDetail_WhenCategoryModelInputIsCorrect_ReturnsSuccess()
        {
            CategoryUpdateModel input = new CategoryUpdateModel()
            {
                Id           = 1,
                CategoryName = "Furniture",
                IsActive     = true
            };

            Mock <ICategoryDataAccess> mockCategories = new Mock <ICategoryDataAccess>();

            mockCategories.Setup(x => x.UpdateCategoryDetails(It.IsAny <Category>())).Returns("Category updated.");

            ICategoryBusinessLayer app = new CategoryBusinessLayer(mockCategories.Object);

            var output = app.UpdateCategoryDetail(input);

            Assert.AreEqual("Category updated.", output);
        }