Пример #1
0
        public ActionResult <Result <CustomerDto> > Post([FromBody] CustomerDto customerDto)
        {
            var customerToPost = new Customer
            {
                Phone          = customerDto.Phone,
                Name           = customerDto.Name,
                AdditionalInfo = customerDto.AdditionalInfo
            };

            var resultFromRepository = customersRepository.Create(customerToPost);

            return(CreatedAtAction(nameof(Get), new { id = resultFromRepository.Value.Id }, new Result <CustomerDto>
            {
                IsSuccess = resultFromRepository.IsSuccess,
                Message = resultFromRepository.Message,
                Value = resultFromRepository.Value != null
                    ? new CustomerDto
                {
                    Id = resultFromRepository.Value.Id,
                    Name = resultFromRepository.Value.Name,
                    Phone = resultFromRepository.Value.Phone,
                    AdditionalInfo = resultFromRepository.Value.AdditionalInfo
                }
                    : null
            }));
        }
Пример #2
0
 public bool Create(客戶資料 customer)
 {
     if (customer == null)
     {
         return(false);
     }
     else
     {
         _customersRepository.Create(customer);
         return(true);
     }
 }
Пример #3
0
        public async Task <IActionResult> CreateCustomer([FromBody] CustomerCreateRequest createCustomerRequest)
        {
            if (createCustomerRequest == null)
            {
                return(BadRequest(new BadRequestResponse("invalid model")));
            }
            if (String.IsNullOrEmpty(createCustomerRequest.FirstName))
            {
                return(BadRequest(new BadRequestResponse("Empty First Name")));
            }
            if (String.IsNullOrEmpty(createCustomerRequest.LastName))
            {
                return(BadRequest(new BadRequestResponse("Empty Last Name")));
            }


            var newCustomer = Mapper.Map <Customer>(createCustomerRequest);

            newCustomer.Id = Guid.NewGuid().ToString("N");
            await _customersRepository.Create(newCustomer);

            return(Ok(Mapper.Map <CustomerResponse>(newCustomer)));
        }
        public OperationResult Create(CreateCustomers command)
        {
            var operation = new OperationResult();

            var picturePath = $"Customers";
            var fileName    = _fileUploader.Upload(command.CustomerLogo, picturePath);

            var customer = new Customers(command.CustomerName, fileName, command.LogoAlt, command.LogoTitle);

            _customersRepository.Create(customer);
            _customersRepository.SaveChanges();

            return(operation.Succedded());
        }
 public IActionResult Create([FromBody] Customer customer)
 {
     _customersRepository.Create(customer);
     return(CreatedAtAction(nameof(GetById), new { id = customer.Id }, customer));
 }
Пример #6
0
 public async Task CreateCustomer(Customer newCustomer)
 {
     await _customersRepository.Create(newCustomer);
 }