コード例 #1
0
        public async Task UpdateCrew(int id, InputCrewDTO item)
        {
            Crew temp = new Crew();

            temp.PilotId = await IunitOfWork.PilotRepository.Get(item.PilotId);

            List <Stewardess> tempS = await IunitOfWork.StewardessRepository.GetAll();

            List <Stewardess> selected = new List <Stewardess>();

            foreach (Stewardess s in tempS)
            {
                foreach (int i in item.StewardessIds)
                {
                    if (s.Id == i)
                    {
                        selected.Add(s);
                    }
                }
            }
            temp.StewardessIds = selected;

            if (temp.StewardessIds.Count == item.StewardessIds.Count() && temp.PilotId != null)
            {
                await IunitOfWork.CrewRepository.Update(id, temp);
            }
            else
            {
                throw new Exception();
            }
        }
コード例 #2
0
        public async Task <IActionResult> Post([FromBody] InputCrewDTO crew)
        {
            if (ModelState.IsValid)
            {
                await crewService.CreateCrew(crew);

                return(Ok(crew));
            }
            else
            {
                return(BadRequest(crew));
            }
        }
コード例 #3
0
        public async Task <IActionResult> Put(int id, [FromBody] InputCrewDTO crew)
        {
            if (ModelState.IsValid)
            {
                //Response.StatusCode = 200;
                await crewService.UpdateCrew(id, crew);

                return(Ok());
            }
            else
            {
                return(BadRequest());
            }
        }