コード例 #1
0
ファイル: CustomersController.cs プロジェクト: Leskyam/Vidly
        public IHttpActionResult PostCustomer(CustomerDto customerDto)
        {
            if (!ModelState.IsValid)
            {
                BadRequest();
            }

            var dbCustomer = _db.Customers.Add(CustomerDto.MapFromCustomerDto(customerDto, new Customer()));

            _db.SaveChanges();

            customerDto.Id = dbCustomer.Id;
            return(Created(new Uri($"{Request.RequestUri}/{dbCustomer.Id}"), customerDto));
        }
コード例 #2
0
ファイル: CustomersController.cs プロジェクト: Leskyam/Vidly
        public IHttpActionResult PutCustomer(CustomerDto customerDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var dbCustomer = _db.Customers.SingleOrDefault(c => c.Id == customerDto.Id);

            if (dbCustomer == null)
            {
                return(NotFound());
            }

            dbCustomer = CustomerDto.MapFromCustomerDto(customerDto, dbCustomer);
            _db.SaveChanges();

            return(Ok(CustomerDto.MapToCustomersDto(new List <Customer>()
            {
                _db.Customers.SingleOrDefault(c => c.Id == dbCustomer.Id)
            }).Single()));
        }