public async Task <int> CreateProductListType(CreateProductListTypeDto model) { if (model != null) { var data = new ProductListType { Name = model.Name, ProductTypeID = model.ProductTypeID }; await _skinHubAppDbContext.AddAsync(data); await _skinHubAppDbContext.SaveChangesAsync(); return(data.ID); } return(0); }
public async Task <IActionResult> Create([FromBody] CreateProductListTypeDto model) { try { if (ModelState.IsValid) { var checkName = await _productTypeServices.IsNameExist(model.Name, model.ProductTypeID); if (checkName == true) { return(BadRequest("Sorry!, This name already exists on our database. Choose another name")); } var createColor = await _productTypeServices.CreateProductListType(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")); } }