示例#1
0
        public IActionResult UpdateClothesCategory(int id, [FromBody] ClothesCategory clothesCategory)
        {
            try
            {
                if (clothesCategory.IsEntityNull())
                {
                    return(BadRequest("ClothesCategory object is null"));
                }

                if (!ModelState.IsValid)
                {
                    return(BadRequest("Invalid model object"));
                }

                ClothesCategory dbClothesCategory = _clothesCategoryService.GetClothesCategoryById(id);
                if (dbClothesCategory.IsEntityNull())
                {
                    _logger.Error($"ClothesCategory with id: {id} not found in db");
                    return(NotFound());
                }

                _clothesCategoryService.UpdateClothesCategory(dbClothesCategory, clothesCategory);
                _clothesCategoryService.Save();

                return(NoContent());
            }
            catch (Exception ex)
            {
                _logger.Error(ex, "Error in call : api/clothesCategory/UpdateClothesCategory/" + id, clothesCategory);
                return(StatusCode(StatusCodes.Status500InternalServerError, "Internal server error"));
            }
        }
示例#2
0
        public IActionResult CreateClothesCategory([FromBody] ClothesCategory clothesCategory)
        {
            try
            {
                if (clothesCategory.IsEntityNull())
                {
                    return(BadRequest("ClothesCategory object is null"));
                }

                if (!clothesCategory.IsEntityEmpty())
                {
                    return(BadRequest("For create, the Id must be null"));
                }

                if (!ModelState.IsValid)
                {
                    return(BadRequest("Invalid model object"));
                }

                _clothesCategoryService.CreateClothesCategory(clothesCategory);
                _clothesCategoryService.Save();

                return(CreatedAtRoute("ClothesCategoryById", new { id = clothesCategory.Id.Value }, clothesCategory));
            }
            catch (Exception ex)
            {
                _logger.Error(ex, "Error in call : api/clothesCategory/CreateClothesCategory", clothesCategory);
                return(StatusCode(StatusCodes.Status500InternalServerError, "Internal server error"));
            }
        }
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync(string[] selectedCategories)
        {
            var newClothes = new Clothes();

            if (selectedCategories != null)
            {
                newClothes.ClothesCategories = new List <ClothesCategory>();
                foreach (var cat in selectedCategories)
                {
                    var catToAdd = new ClothesCategory
                    {
                        CategoryID = int.Parse(cat)
                    };
                    newClothes.ClothesCategories.Add(catToAdd);
                }
            }
            if (await TryUpdateModelAsync <Clothes>(
                    newClothes,
                    "Clothes",
                    i => i.Name, i => i.Size,
                    i => i.Price, i => i.DateOfAppearance, i => i.BrandID))
            {
                _context.Clothes.Add(newClothes);
                await _context.SaveChangesAsync();

                return(RedirectToPage("./Index"));
            }
            PopulateAssignedCategoryData(_context, newClothes);
            return(Page());
        }
 public static void ApplyChange(this ClothesCategory dbClothesCategory, ClothesCategory clothesCategory)
 {
     if (!String.IsNullOrWhiteSpace(clothesCategory.Code))
     {
         dbClothesCategory.Code = clothesCategory.Code;
     }
     if (!String.IsNullOrWhiteSpace(clothesCategory.Label))
     {
         dbClothesCategory.Label = clothesCategory.Label;
     }
 }
示例#5
0
        public IActionResult GetClothesCategoryById(int id)
        {
            try
            {
                ClothesCategory clothesCategory = _clothesCategoryService.GetClothesCategoryById(id);
                if (clothesCategory == null)
                {
                    _logger.Error($"ClothesCategory with id: {id} not found in db");
                    return(NotFound());
                }

                return(Ok(clothesCategory));
            }
            catch (Exception ex)
            {
                _logger.Error(ex, "Error in call : api/clothesCategory/GetClothesCategoryById/" + id.ToString());
                return(StatusCode(StatusCodes.Status500InternalServerError, "Internal server error"));
            }
        }
示例#6
0
        public IActionResult DeleteClothesCategory(int id)
        {
            try
            {
                ClothesCategory clothesCategory = _clothesCategoryService.GetClothesCategoryById(id);
                if (clothesCategory.IsEntityNull())
                {
                    _logger.Error($"ClothesCategory with id: {id} not found in db");
                    return(NotFound());
                }

                _clothesCategoryService.DeleteClothesCategory(clothesCategory);
                _clothesCategoryService.Save();

                return(NoContent());
            }
            catch (Exception ex)
            {
                _logger.Error(ex, "Error in call : api/clothesCategory/DeleteClothesCategory/" + id);
                return(StatusCode(StatusCodes.Status500InternalServerError, "Internal server error"));
            }
        }
 public void UpdateClothesCategory(ClothesCategory dbClothesCategory, ClothesCategory clothesCategory)
 {
     _clothesCategoryRepository.UpdateClothesCategory(dbClothesCategory, clothesCategory);
 }
 public void DeleteClothesCategory(ClothesCategory clothesCategory)
 {
     _clothesCategoryRepository.DeleteClothesCategory(clothesCategory);
 }
 public void CreateClothesCategory(ClothesCategory clothesCategory)
 {
     _clothesCategoryRepository.Create(clothesCategory);
 }