public async Task <Diet> Create(Diet diet) { List <Task> tasks = new List <Task>(); var planIdExists = _planRepository.GetById(diet.SuitablePlanId); tasks.Add(planIdExists); var uniqueId = _dietRepository.GetById(diet.Id); tasks.Add(uniqueId); var uniqueName = _dietRepository.GetByName(diet.Name); tasks.Add(uniqueName); await Task.WhenAll(tasks); if (planIdExists.Result != null && uniqueId.Result == null && uniqueName.Result == null) { return(await _dietRepository.Create(diet)); } else { throw new Exception(); } }
public async Task <ActionResult <int> > Create([FromBody] DietViewModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } return(await dietRepository.Create(model)); }
public async Task Create(DietDto entityDto) { await _dietRepository.Create(entityDto); }