public void CustomerDelete() { var db = new TestDb(); db.AddSet(TestData.Customers); // Arrange CustomerController controller = new CustomerController(db); CustomerModel testCustomer = new CustomerModel(); testCustomer.Id = 8; testCustomer.Email = "*****@*****.**"; testCustomer.FirstName = "User First Name"; testCustomer.MiddleName = "User Middle Name"; testCustomer.LastName = "User Last Name"; testCustomer.Gender = "M"; testCustomer.Address = "The World"; testCustomer.BirthDate = DateTime.UtcNow.Date; testCustomer.MaritalStatus = "M"; testCustomer.SourceOfIncome = "Employed"; testCustomer.IsDeleted = false; testCustomer.CreateDate = DateTime.UtcNow.Date; testCustomer.UpdateDate = DateTime.UtcNow.Date; // Act // var result = controller.Delete(testCustomer); // Assert //Assert.IsNotNull(result); }
public IHttpActionResult Post(CustomerModel customer) { try { //var c = db.Query<CustomerModel>().ToList().LastOrDefault(); CustomerModel newCustomer = new CustomerModel(); newCustomer.Email = customer.Email; newCustomer.FirstName = customer.FirstName; newCustomer.LastName = customer.LastName; newCustomer.MiddleName = customer.MiddleName; newCustomer.Gender = customer.Gender; newCustomer.Address = customer.Address; newCustomer.BirthDate = customer.BirthDate.Date; newCustomer.MaritalStatus = customer.MaritalStatus; newCustomer.SourceOfIncome = customer.SourceOfIncome; newCustomer.IsDeleted = false; newCustomer.CreateDate = DateTime.Now; newCustomer.UpdateDate = DateTime.Now; db.Add(newCustomer); return Ok(); } catch (HttpResponseException e) { return NotFound(); } }
public IHttpActionResult Put(CustomerModel customer) { try { CustomerModel c = db.Query<CustomerModel>().Where(x => x.Email == customer.Email && x.IsDeleted == false).FirstOrDefault(); if (c == null) { return NotFound(); } else { //c.Id = customer.Id; //c.Email = customer.Email; c.FirstName = customer.FirstName; c.LastName = customer.LastName; c.MiddleName = customer.MiddleName; c.Gender = customer.Gender; c.Address = customer.Address; c.BirthDate = customer.BirthDate.Date; c.MaritalStatus = customer.MaritalStatus; c.SourceOfIncome = customer.SourceOfIncome; c.UpdateDate = DateTime.Now; db.SaveChanges(c); return Ok(); } } catch (HttpResponseException e) { return NotFound(); } }