예제 #1
0
        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();
            }
        }
예제 #2
0
        public async Task <ActionResult <int> > Create([FromBody] DietViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            return(await dietRepository.Create(model));
        }
예제 #3
0
 public async Task Create(DietDto entityDto)
 {
     await _dietRepository.Create(entityDto);
 }