public async Task <IActionResult> CreateColorWatch(ColorWatchDTO_ToCreate create) { var result = await _colorWatch.CreateColorWatch(create); if (result.IsSuccess) { return(Ok(result)); } else { throw new Exception(result.Message); } }
public async Task <ServiceResponse <ColorWatchDTO_ToReturn> > CreateColorWatch(ColorWatchDTO_ToCreate create) { var checkColorWatch = await(_dbContext.ColorWatchs.Where(x => x.Color == create.Color).FirstOrDefaultAsync()); if (checkColorWatch != null) { return(ResponseResult.Failure <ColorWatchDTO_ToReturn>("Can't CrateDetailWatch")); } var createColorWatch = new Models.ColorWatch(); createColorWatch.Color = create.Color; createColorWatch.CreateDate = DateTime.Now; await _dbContext.ColorWatchs.AddAsync(createColorWatch); await _dbContext.SaveChangesAsync(); var resultToReturn = _mapper.Map <ColorWatchDTO_ToReturn>(createColorWatch); return(ResponseResult.Success(resultToReturn)); }