public async Task <IActionResult> CreateDetailWatch(DetailWatchDTO_ToCreate create) { var result = await _detailWatch.CreateDetailWatch(create); if (result.IsSuccess) { return(Ok(result)); } else { throw new Exception(result.Message); } }
public async Task <ServiceResponse <DetailWatchDTO_ToReturn> > CreateDetailWatch(DetailWatchDTO_ToCreate create) { var checkDetailWatch = await(_dbContext.DetailWatchs.Where(x => x.ColorId == create.ColorId).FirstOrDefaultAsync()); if (checkDetailWatch != null) { return(ResponseResult.Failure <DetailWatchDTO_ToReturn>("Can't CrateDetailWatch")); } var createDetailWatch = new Models.DetailWatch(); createDetailWatch.ColorId = create.ColorId; createDetailWatch.CreateDate = DateTime.Now; await _dbContext.DetailWatchs.AddAsync(createDetailWatch); await _dbContext.SaveChangesAsync(); var resultToReturn = _mapper.Map <DetailWatchDTO_ToReturn>(createDetailWatch); return(ResponseResult.Success(resultToReturn)); }