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