コード例 #1
0
        public async Task Add(CarGroupAddDto carGroupDto)
        {
            var carGroupRepository = DataContextManager.CreateRepository <ICarGroupRepository>();

            var carGroup = await carGroupRepository.GetByName(carGroupDto.Name);

            if (carGroup != null)
            {
                throw new AddingException();
            }

            var carSubgroupRepository = DataContextManager.CreateRepository <ICarSubgroupRepository>();
            var carSubgroups          = await carSubgroupRepository.GetByIds(carGroupDto.CarSubgroupIds);

            var newCarGroup = new CarGroup
            {
                Name                   = carGroupDto.Name,
                CreateDate             = DateTime.Now,
                CarSubgroupInCarGroups = carSubgroups.Select(carSubgroup => new CarSubgroupInCarGroup
                {
                    CarSubgroup = carSubgroup
                })
                                         .ToList()
            };

            await carGroupRepository.Add(newCarGroup);
        }
コード例 #2
0
        public async Task <ActionResult> AddCarGroup([FromBody] CarGroupAddDto carGroup)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            try
            {
                await _carGroupService.Add(carGroup);

                return(Ok());
            }
            catch (AddingException aex)
            {
                _log.Error(aex);
                return(StatusCode((int)HttpStatusCode.Forbidden, ErrorMessage.SAMENAME.ToString()));
            }
        }