public IActionResult CreateManufacturer([FromBody] CreateManufacturerModel model)
 {
     try
     {
         if (ModelState.IsValid)
         {
             var createResponse = _manufacturerRepository.Create(model.ToEntity());
             if (createResponse.StatusCode != 201)
             {
                 return(StatusCode(createResponse.StatusCode));
             }
             else
             {
                 return(StatusCode(createResponse.StatusCode, ManufacturerModel.ToModel(createResponse.Data)));
             }
         }
         else
         {
             return(BadRequest());
         }
     }
     catch (Exception e)
     {
         return(InternalServerError());
     }
 }
コード例 #2
0
        public async Task <IActionResult> Create([FromBody] ManufacturerCreateDTO manufacturerDTO)
        {
            try
            {
                if (manufacturerDTO == null)
                {
                    return(BadRequest(ModelState));
                }
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }
                var manufacturer = _mapper.Map <Manufacturer>(manufacturerDTO);
                var isSuccess    = await _manufacturerRepository.Create(manufacturer);

                if (!isSuccess)
                {
                    return(InternalError($"Creation failed"));
                }
                return(Created("Create", new { manufacturer }));
            }
            catch (Exception e)
            {
                return(InternalError($"{e.Message} - {e.InnerException}"));
            }
        }
コード例 #3
0
        public ManufacturerDto Create(ManufacturerDto dto)
        {
            var manufacturer = Mapper.Map <ManufacturerDto, Manufacturer>(dto);

            _manufacturerRepository.Create(manufacturer);

            return(Mapper.Map <Manufacturer, ManufacturerDto>(_manufacturerRepository.FindById(manufacturer.Id)));
        }
コード例 #4
0
        public Manufacturer Create(Manufacturer manufacturer)
        {
            if (string.IsNullOrEmpty(manufacturer.Name))
            {
                throw new ArgumentException("Name cannot be null or empty");
            }

            return(_manufacturerRepository.Create(manufacturer));
        }
コード例 #5
0
        public IBaseCommandResult Handle(CreateManufacturerCommand command)
        {
            command.Validate();
            if (command.Invalid)
            {
                return(new BaseCommandResult(false, "Need to fix the errors on Manufacturer", command.Notifications));
            }

            var manufacturer = new Manufacturer(command.Description);

            _repository.Create(manufacturer);

            return(new BaseCommandResult(true, "Manufacturer Saved with Success!", manufacturer));
        }
コード例 #6
0
        public ResponseMessage <Manufacturer> Create(Manufacturer entity)
        {
            ResponseMessage <Manufacturer> response = new ResponseMessage <Manufacturer>();

            try
            {
                response.ResponseObject = _manufacturerRepository.Create(entity);
                response.IsSuccess      = true;
                response.ErrorMessage   = "Success";
            }
            catch (Exception ex)
            {
                response.IsSuccess    = false;
                response.ErrorMessage = ex.Message;
            }

            return(response);
        }
コード例 #7
0
        public IBaseCommandResult Handle(CreateEquipmentCommand command)
        {
            command.Validate();
            if (command.Invalid)
            {
                return(new BaseCommandResult(false, "Need to fix the errors on Equipment", command.Notifications));
            }

            var user = _userRepository.GetById(command.UserId);

            if (user == null)
            {
                return(new BaseCommandResult(false, "User not found", null));
            }

            //logic here: if manufacturer and/or model don't exists, i will create it and attach to equipment
            var manufacturer = _manufacturerRepository.GetByDescription(command.Manufacturer);

            if (manufacturer == null)
            {
                manufacturer = new Manufacturer(command.Manufacturer);
                _manufacturerRepository.Create(manufacturer);
            }

            var deviceModel = _deviceModelRepository.GetByDescriptionAndManufacturer(command.Model, manufacturer);

            if (deviceModel == null)
            {
                deviceModel = new DeviceModel(command.Model, manufacturer);
                _deviceModelRepository.Create(deviceModel);
            }

            var equipment = new Equipment(command.AndroidId, command.Imei1, command.Imei2, command.PhoneNumber, command.MacAddress,
                                          command.ApiLevel, command.ApiLevelDesc, command.SerialNumber, command.SystemName, command.SystemVersion, deviceModel, user);

            _repository.Create(equipment);

            return(new BaseCommandResult(true, "Equipment Saved with Success!", new { Id = equipment.Id.ToString() }));
        }