public void Add(User entity) { using (IDbConnection cn = connection) { var parameters = new { FirstName = entity.FirstName, LastName = entity.LastName, Email = entity.Email, AddressLine1 = entity.AddressLine1, City = entity.City, PostCode = entity.PostCode, Country = entity.Country, Phone = entity.Phone, Id = entity.Id }; cn.Open(); entity.Id = cn.Query<Guid>( "INSERT INTO Users (FirstName, LastName, Email, AddressLine1,City,PostCode,Country,Phone, Id) VALUES(@FirstName, @LastName, @Email, @AddressLine1,@City,@PostCode,@Country,@Phone, @Id)", parameters).FirstOrDefault(); } }
public void Update(User entity) { using (IDbConnection cn = connection) { var parameters = new { FirstName = entity.FirstName, LastName = entity.LastName, Email = entity.Email, AddressLine1 = entity.AddressLine1, City = entity.City, PostCode = entity.PostCode, Country = entity.Country, Phone = entity.Phone, Id = entity.Id }; cn.Open(); cn.Execute( "UPDATE Users SET FirstName=@FirstName, LastName=@LastName, Email=@Email, AddressLine1=@AddressLine1, City=@City, PostCode=@PostCode, Country=@Country, Phone = @Phone WHERE Id=@Id", parameters); } }
public void AddPricingQueryTest() { // We use a static id, so we always can drop the the user after the test Guid userid = new Guid("f265ab67-8006-4266-b6fd-c6a409321b31"); // We use a static id, so we always can drop the the query after the test Guid queryid = new Guid("329BF626-9F06-483B-AD0F-F70E27BE30F7"); // We use a static id, so we always can drop the the query after the test Guid productid = new Guid("758c0953-e576-4a8d-9223-b85ffd24c8ac"); //Add User User user = new User() { Id = userid, FirstName = "Jayakaran", LastName = "Theiven", AddressLine1 = "buntspechtweg 8a", City = "Bonn", PostCode = "53123", Country = "Germany", Email ="*****@*****.**", Phone = "00491739476008"}; userRepository.Add(user); //Add Product Product product = new Product() { Id = productid, Name = "Test Product" }; productRepository.Add(product); //insert pricing query PricingQuery query = new PricingQuery() { Id = queryid, ProductId = productid, UserId = userid, EnquiryDate = DateTime.Today, IsReplied = false }; pricingQueryRepository.Add(query); // return pricing query data and test var result = pricingQueryRepository.Find(queryid); Assert.That(result.Id, Is.EqualTo(queryid)); Assert.That(result.UserId, Is.EqualTo(userid)); Assert.That(result.ProductId, Is.EqualTo(productid)); //Clean up after testing PricingQueryCleanUp(queryid); UserCleanUp(userid); ProductCleanUp(productid); }
// private methods private User UpdateExistingUser(User user, PricingQueryViewModel model) { if (model.FirstName != "") user.FirstName = model.FirstName; if (model.LastName != "") user.LastName = model.LastName; if (model.AddressLine1 != "") user.AddressLine1 = model.AddressLine1; if (model.City != "") user.City = model.City; if (model.PostCode != "") user.PostCode = model.PostCode; if (model.Country != "") user.Country = model.Country; if (model.Phone != "") user.Phone = model.Phone; return user; }