Beispiel #1
0
        public async Task <int> CreateProductType(CreateProductTypeDto model)
        {
            if (model != null)
            {
                var data = new ProductType
                {
                    Name        = model.Name,
                    ColorTypeID = model.ColorTypeID
                };
                await _skinHubAppDbContext.AddAsync(data);

                await _skinHubAppDbContext.SaveChangesAsync();

                return(data.ID);
            }
            return(0);
        }
Beispiel #2
0
        public async Task <IActionResult> Create([FromBody] CreateProductTypeDto model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var checkName = await _productTypeServices.IsNameExist(model.Name, model.ColorTypeID);

                    if (checkName == true)
                    {
                        return(BadRequest("Sorry!, This name already exists on our database. Choose another name"));
                    }

                    var createColor = await _productTypeServices.CreateProductType(model);

                    return(StatusCode(201, $"{model.Name} created Successfully."));
                }
                return(BadRequest("Sorry! Your task cannot be completed"));
            }
            catch (Exception ex)
            {
                return(BadRequest($"{ex.Message}, Error! Your task failed, Please try again"));
            }
        }