Exemple #1
0
        public async Task <IActionResult> CreateSpecialist([FromBody] SaveSpecialistResource specialistResource)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var companies = await repository.GetListOfCompaniesIds();

            foreach (var i in specialistResource.Companies)
            {
                if (!companies.Contains(i))
                {
                    return(BadRequest("Wrong company code provided"));
                }
            }

            var specialist = mapper.Map <SaveSpecialistResource, Specialist>(specialistResource);

            specialist.Details.DateOfRegistration = DateTime.Now;

            repository.Add(specialist);
            await unitOfWork.CompleteAsync();

            specialist = await repository.GetSpecialist(specialist.Id);

            var result = mapper.Map <Specialist, SpecialistResource>(specialist);

            return(Ok(result));
        }