public IActionResult UpdateCustomerById(Guid id, [FromBody] BaseCustomer customer)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id == Guid.Empty)
            {
                return(BadRequest("No valid Guid provided for Update Action"));
            }

            if (customer == null)
            {
                return(BadRequest("No Customer provided, can't execute Update Action"));
            }

            var currentCustomer = _ctx.Customers.FirstOrDefault(c => c.Id == id);

            if (currentCustomer == null)
            {
                return(NotFound($"No customer found with id {id}"));
            }

            currentCustomer.FirstName = customer.FirstName;
            currentCustomer.LastName  = customer.LastName;
            _ctx.SaveChanges();

            return(Ok(currentCustomer));
        }
Beispiel #2
0
 public static BaseCustomer Create(string customerName)
 {
     //We did lazy loading here, when needed then only we Loading customer collection.
     BaseCustomer.LoadCustomers();
     //It replaced to check conditions, used Replace If with Polymorphism(RIP) Condition.
     return(baseCustomer[customerName]);
 }
        public void TestType4()
        {
            // Arrange
            sut = new Type4Customer(6);
            // Act
            var actual = sut.Calculate(500);

            // Assert
            Assert.AreEqual(237.500m, actual);
        }
        public void TestType1()
        {
            // Arrange
            sut = new DefaultCustomer(6);
            // Act
            var actual = sut.Calculate(500);

            // Assert
            Assert.AreEqual(500, actual);
        }