コード例 #1
0
ファイル: CastToCustomerDto.cs プロジェクト: jeffward01/test
 public static Customer CastToDbo(Customer_Dto customer)
 {
     return(new Customer
     {
         CustomerId = customer.CustomerId,
         FirstName = customer.FirstName,
         IsActive = customer.IsActive,
         LastName = customer.LastName,
         MiddleName = customer.MiddleName
     });
 }
コード例 #2
0
        public IHttpActionResult CreateCustomer(Customer_Dto customerDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var customer = Mapper.Map <Customer_Dto, Customer>(customerDto);

            _context.Customers.Add(customer);
            _context.SaveChanges();

            customerDto.Id = customer.Id;

            return(Created(new Uri(Request.RequestUri + "/" + customer.Id), customerDto));
        }
コード例 #3
0
        public void UpdateCustomer(int id, Customer_Dto customerDto)
        {
            if (!ModelState.IsValid)
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }


            var CustomerInDb = _context.Customers.SingleOrDefault(c => c.Id == id);

            if (CustomerInDb == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }

            Mapper.Map(customerDto, CustomerInDb);

            _context.SaveChanges();
        }