Example #1
0
        public IActionResult UpdateClothesSize(int id, [FromBody] ClothesSize clothesSize)
        {
            try
            {
                if (clothesSize.IsEntityNull())
                {
                    return(BadRequest("ClothesSize object is null"));
                }

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

                ClothesSize dbClothesSize = _clothesSizeService.GetClothesSizeById(id);
                if (dbClothesSize.IsEntityNull())
                {
                    _logger.Error($"ClothesSize with id: {id} not found in db");
                    return(NotFound());
                }

                _clothesSizeService.UpdateClothesSize(dbClothesSize, clothesSize);
                _clothesSizeService.Save();

                return(NoContent());
            }
            catch (Exception ex)
            {
                _logger.Error(ex, "Error in call : api/clothesSize/UpdateClothesSize/" + id, clothesSize);
                return(StatusCode(StatusCodes.Status500InternalServerError, "Internal server error"));
            }
        }
Example #2
0
        public async Task AddAsync(
            string userId,
            string name,
            ClothesType type,
            int quantity,
            ClothesSize size,
            double singlePrice,
            string pictureUrl,
            string description)
        {
            var clothes = new Clothes
            {
                Name        = name,
                Type        = type,
                Quantity    = quantity,
                Size        = size,
                SinglePrice = singlePrice,
                PictureUrl  = pictureUrl,
                Description = description,
                OwnerId     = userId
            };

            this.db.Add(clothes);
            await this.db.SaveChangesAsync();
        }
Example #3
0
        public IActionResult CreateClothesSize([FromBody] ClothesSize clothesSize)
        {
            try
            {
                if (clothesSize.IsEntityNull())
                {
                    return(BadRequest("ClothesSize object is null"));
                }

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

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

                _clothesSizeService.CreateClothesSize(clothesSize);
                _clothesSizeService.Save();

                return(CreatedAtRoute("ClothesSizeById", new { id = clothesSize.Id.Value }, clothesSize));
            }
            catch (Exception ex)
            {
                _logger.Error(ex, "Error in call : api/clothesSize/CreateClothesSize", clothesSize);
                return(StatusCode(StatusCodes.Status500InternalServerError, "Internal server error"));
            }
        }
Example #4
0
        public void CreateClothesSize(ClothesSize clothesSize)
        {
            var existingClothesSize = _clothesSizeRepository.GetClothesSizeBySizeIdAndClothesId(clothesSize.SizeId, clothesSize.ClothesId);

            if (existingClothesSize == null)
            {
                _clothesSizeRepository.Create(clothesSize);
            }
            else
            {
                clothesSize.Id = existingClothesSize.Id;
            }
        }
Example #5
0
        public IActionResult GetClothesSizeById(int id)
        {
            try
            {
                ClothesSize clothesSize = _clothesSizeService.GetClothesSizeById(id);
                if (clothesSize == null)
                {
                    _logger.Error($"ClothesSize with id: {id} not found in db");
                    return(NotFound());
                }

                return(Ok(clothesSize));
            }
            catch (Exception ex)
            {
                _logger.Error(ex, "Error in call : api/clothesSize/GetClothesSizeById/" + id.ToString());
                return(StatusCode(StatusCodes.Status500InternalServerError, "Internal server error"));
            }
        }
Example #6
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            //description can't be null
            if (string.IsNullOrEmpty(txtDescription.Text.Trim()))
            {
                MessageBox.Show("Input description...");
                txtDescription.Focus();
                return;
            }
            //to save clothes size
            var clothes = new ClothesSize()
            {
                Size     = txtDescription.Text,
                IsActive = true
            };

            db.ClothesSizes.Add(clothes);
            db.SaveChanges();
            this.LoadData();
            MessageBox.Show("Saved...");
        }
Example #7
0
        public IActionResult DeleteClothesSize(int id)
        {
            try
            {
                ClothesSize clothesSize = _clothesSizeService.GetClothesSizeById(id);
                if (clothesSize.IsEntityNull())
                {
                    _logger.Error($"ClothesSize with id: {id} not found in db");
                    return(NotFound());
                }

                _clothesSizeService.DeleteClothesSize(clothesSize);
                _clothesSizeService.Save();

                return(NoContent());
            }
            catch (Exception ex)
            {
                _logger.Error(ex, "Error in call : api/clothesSize/DeleteClothesSize/" + id);
                return(StatusCode(StatusCodes.Status500InternalServerError, "Internal server error"));
            }
        }
Example #8
0
        public async Task EditAsync(
            int id,
            string name,
            ClothesType type,
            int quantity,
            ClothesSize size,
            double singlePrice,
            string pictureUrl,
            string description)
        {
            var product = await this.db.Clothes.FindAsync(id);

            product.Name        = name;
            product.Type        = type;
            product.Quantity    = quantity;
            product.Size        = size;
            product.SinglePrice = singlePrice;
            product.PictureUrl  = pictureUrl;
            product.Description = description;

            await this.db.SaveChangesAsync();
        }
Example #9
0
 public void UpdateClothesSize(ClothesSize dbClothesSize, ClothesSize clothesSize)
 {
     _clothesSizeRepository.UpdateClothesSize(dbClothesSize, clothesSize);
 }
Example #10
0
 public void DeleteClothesSize(ClothesSize clothesSize)
 {
     _clothesSizeRepository.DeleteClothesSize(clothesSize);
 }