public void getCustomerByIdTest() { Mock <ICustomerRepo> cusRepoMock = new Mock <ICustomerRepo>(); ICustomer cus1 = new Model.Customer(1, "A", null, "Z"); ICustomer cus2 = new Model.Customer(2, "B", "S", "Y"); cusRepoMock.Setup(x => x.getCustomerById(1)).Returns(cus1); cusRepoMock.Setup(x => x.getCustomerById(2)).Returns(cus2); var cusRepo = new nUnitWithCSharp.Customer(cusRepoMock.Object); Assert.IsNotNull(cusRepo, "Customer repository object not initiated correctly."); var cus3 = cusRepo.getCustomerById(1); Assert.IsNotNull(cus3, "Customer object not initiated correctly."); Assert.IsNotNull(cus3.fullName, "Customer full name not correct."); Assert.AreEqual(cus3.fullName, "A Z", "Customer full name not correct."); var cus4 = cusRepo.getCustomerById(2); Assert.AreEqual(cus4.fullName, "B S Y", "Customer full name not correct."); var cus5 = cusRepo.getCustomerById(0); Assert.IsNull(cus5, "Customer object is incorrectly initiated"); }
static void Main(string[] args) { using(var salesUnitOfWork = new SalesUnitOfWork("Sales")) { var customer = new Customer { FirstName = "John", LastName = "Smith" }; var order = new Order {Date = DateTime.Now}; order.OrderItems.Add(new OrderItem {Price = 101}); customer.Orders.Add(order); salesUnitOfWork.Customers.Add(customer); salesUnitOfWork.Commit(); var customers = salesUnitOfWork.Customers .FindAll() .Include("Orders.OrderItems") .Where(c => c.Orders.Any(o => o.OrderItems.Any(oi => oi.Price > 100))) .OrderBy(c => c.FirstName) .Take(10) .ToList(); foreach (var c in customers) { System.Console.WriteLine(c.FirstName); foreach (var o in c.Orders) { System.Console.WriteLine(o.Date); } } } }
/// <summary> /// 添加客户 /// </summary> /// <param name="customer"></param> /// <param name="error"></param> /// <returns></returns> public static bool AddCustomer(Model.Customer customer, ref string error) { if (IsExit(customer.CustomerId)) { error = "已存在该客户编号!请重新填写客户编号。"; return(false); } if (string.IsNullOrEmpty(customer.CustomerId) || string.IsNullOrEmpty(customer.CustomerName)) { error = "客户信息不完整!"; return(false); } string sql = string.Format(@" insert into Customer (CustomerId,CustomerName,RegisteredAddress, LegalPerson,Contacts,RegisteredPhone,ContactTelephone,Fax, MobilePhone,ZipCode,SparePhone,Email,QQ,AccountBank,SortCode,BankAccount,TaxNo,WebsiteAddress, DeliveryAddress,Paymentdays,PercentageInAdvance,Remark,factoryaddress,MakeCollectionsModeId,ReceiveType) values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}','{16}','{17}', '{18}','{19}','{20}','{21}','{22}','{23}','{24}') ", customer.CustomerId, customer.CustomerName, customer.RegisteredAddress, customer.LegalPerson, customer.Contacts, customer.RegisteredPhone, customer.ContactTelephone, customer.Fax, customer.MobilePhone, customer.ZipCode, customer.SparePhone, customer.Email, customer.QQ, customer.AccountBank, customer.SortCode, customer.BankAccount, customer.TaxNo, customer.WebsiteAddress, customer.DeliveryAddress, customer.Paymentdays, customer.PercentageInAdvance, customer.Remark, customer.FactoryAddress, customer.MakeCollectionsModeId, customer.ReceiveType); return(SqlHelper.ExecuteSql(sql, ref error)); }
/// <summary> /// 用户修改密码方法() /// </summary> /// <param name="customer">用户输入的信息集合</param> /// <returns>数据库中受影响的行数,如果大于0,则密码修改成功!,否则失败!</returns> public static int UpdateCustomerPwd(Model.Customer customer) { SqlParameter[] P = { new SqlParameter("@ID", customer.ID), new SqlParameter("@Pwd", customer.Password), }; return(DBHelper.ExecuteNonQuery("P_CustomerChangePwd", System.Data.CommandType.StoredProcedure, P)); }
private static CustomerViewModel Convert(Customer lomoConfigViewModel) { if (lomoConfigViewModel == null) { throw new ArgumentNullException("lomoConfigViewModel"); } return new CustomerViewModel { Id = lomoConfigViewModel.Id, Name = lomoConfigViewModel.Name }; }
/// <summary> /// 新用户注册方法() /// </summary> /// <param name="customer">用户输入的信息集合</param> /// <returns>数据库中受影响的行数,如果大于0,则注册成功!,否则注册失败!</returns> public static int InsertCustomer(Model.Customer customer) { string sql = " insert into Customer([ID],[LoginName],[Password],[Emial]) values(@ID,@LoginName,@Pwd,@emial)"; SqlParameter[] P = { new SqlParameter("@ID", System.Guid.NewGuid().ToString()), new SqlParameter("@LoginName", customer.LoginName), new SqlParameter("@Pwd", customer.Password), new SqlParameter("@emial", customer.Emial), }; return(DBHelper.ExecuteNonQuery(sql, System.Data.CommandType.Text, P)); }
public static IRoutesRepository MockRoutesRepository() { var mockRoutesRepository = new Mock<IRoutesRepository>(); Customer customer = new Customer(); List<Route> routes = new List<Route>(); routes.Add(new Route { Comments="", Created = DateTime.Now, CreatedBy = "cvazquez", ID = 1, Name = "NOMBRE", IsDeleted = false, Distance = 1000, Customer = customer}); routes.Add(new Route { Comments="", Created = DateTime.Now, CreatedBy = "cvazquez2", ID = 2, Name = "NOMBRE2", IsDeleted = false, Distance = 1001, Customer = customer}); mockRoutesRepository.Setup(x=>x.GetByID(1)).Returns(routes[0]); //TODO: Throw Exception //mockRoutesRepository.Setup(x=>x.GetByID(2)).Returns(); mockRoutesRepository.Setup(x=>x.GetAll()).Returns(routes); return mockRoutesRepository.Object; }
static void CreateCustomer_01(MyShuttleContext context) { var customer = new Customer { Address = "15010 NE 36th Street", City = "Redmond", Country = "United States", CompanyID = "1234-344", Email = "*****@*****.**", Name = "Microsoft", Phone = "555-555-555", State = "Washington", ZipCode = "98052" }; context.Customers.Add(customer); context.SaveChanges(); CreateEmployees(customer.CustomerId, context); }
public bool PostCustomerQuestion(CustomerQuestionVM customerQuestion) { try { var inEmail = customerQuestion.CustomerEmail; var inName = customerQuestion.CustomerEmail; var newCustomerQuestion = new CustomerQuestion() { CategoryId = customerQuestion.CategoryId, QuestionText = customerQuestion.QuestionText, }; int cid = FindCustomer(inName, inEmail); if (cid == -1) { Customer newCustomer = new Customer() { Email = inEmail, FullName = inName }; SaveCustomer(newCustomer); cid = FindCustomer(inName, inEmail); } newCustomerQuestion.CustomerId = cid; _db.CustomerQuesions.Add(newCustomerQuestion); _db.SaveChanges(); return true; } catch (Exception e) { return false; } }
public bool SaveCustomer(Customer customer) { try { // lagre kunden _db.Customers.Add(customer); _db.SaveChanges(); } catch (Exception e) { return false; } return true; }
/// <summary> /// Create a new Customer object. /// </summary> /// <param name="id">Initial value of the Id property.</param> /// <param name="firstName">Initial value of the FirstName property.</param> /// <param name="lastName">Initial value of the LastName property.</param> /// <param name="emailAddress">Initial value of the EmailAddress property.</param> /// <param name="password">Initial value of the Password property.</param> /// <param name="contactNumber">Initial value of the ContactNumber property.</param> /// <param name="createdAt">Initial value of the CreatedAt property.</param> public static Customer CreateCustomer(global::System.Int32 id, global::System.String firstName, global::System.String lastName, global::System.String emailAddress, global::System.String password, global::System.String contactNumber, global::System.DateTime createdAt) { Customer customer = new Customer(); customer.Id = id; customer.FirstName = firstName; customer.LastName = lastName; customer.EmailAddress = emailAddress; customer.Password = password; customer.ContactNumber = contactNumber; customer.CreatedAt = createdAt; return customer; }
/// <summary> /// 新用户注册方法() /// </summary> /// <param name="customer">用户输入的信息集合</param> /// <returns>数据库中受影响的行数,如果大于0,则注册成功!,否则注册失败!</returns> public static int InsertCustomer(Model.Customer customer) { return(DAL.CustomerDAL.InsertCustomer(customer)); }
void MainWindow_Loaded(object sender, RoutedEventArgs e) { _context = new CompanyContext(); _customer = _context.Customers.First(); Formulaire.DataContext = _customer; }
/// <summary> /// 用户修改密码方法() /// </summary> /// <param name="customer">用户输入的信息集合</param> /// <returns>数据库中受影响的行数,如果大于0,则密码修改成功!,否则失败!</returns> public static int UpdateCustomerPwd(Model.Customer customer) { return(DAL.CustomerDAL.UpdateCustomerPwd(customer)); }
/// <summary> /// Deprecated Method for adding a new object to the Customers EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToCustomers(Customer customer) { base.AddObject("Customers", customer); }
protected void btnSubmit_Click(object sender, EventArgs e) { string error = string.Empty; Model.Customer customer = new Model.Customer(); customer.CustomerId = this.txtCustomerNumber.Text.Trim(); customer.CustomerName = this.txtCustomerName.Text.Trim(); customer.RegisteredAddress = this.txtRegisteredAddress.Text.Trim(); customer.LegalPerson = this.txtLegalPerson.Text.Trim(); customer.Contacts = this.txtContacts.Text.Trim(); customer.RegisteredPhone = this.txtRegisteredPhone.Text.Trim(); customer.ContactTelephone = this.txtContactTelephone.Text.Trim(); customer.Fax = this.txtFax.Text.Trim(); customer.MobilePhone = this.txtMobilePhone.Text.Trim(); customer.ZipCode = this.txtZipCode.Text.Trim(); customer.SparePhone = this.txtSparePhone.Text.Trim(); customer.Email = this.txtEmail.Text.Trim(); customer.QQ = this.txtQQ.Text.Trim(); customer.AccountBank = this.txtAccountBank.Text.Trim(); customer.SortCode = this.txtSortCode.Text.Trim(); customer.BankAccount = this.txtBankAccount.Text.Trim(); customer.TaxNo = this.txtTaxNo.Text.Trim(); customer.WebsiteAddress = this.txtWebsiteAddress.Text.Trim(); customer.DeliveryAddress = this.txtDeliveryAddress.Text.Trim(); customer.Paymentdays = 0; customer.PercentageInAdvance = 0; customer.Remark = this.txtRemark.Text.Trim(); customer.FactoryAddress = this.txtFactoryAddress.Text.Trim(); customer.MakeCollectionsModeId = this.drpMakeCollectionsModeId.SelectedValue; customer.ReceiveType = this.drpReceiveType.SelectedValue; if (string.IsNullOrEmpty(customer.CustomerId) || string.IsNullOrEmpty(customer.CustomerName)) { lbSubmit.Text = "请将带*号的内容填写完整!"; return; } bool result = false; if (btnSubmit.Text.Equals("添加")) { result = CustomerInfoManager.AddCustomer(customer, ref error); lbSubmit.Text = result == true ? "添加成功" : "添加失败!原因" + error; if (result) { Tool.WriteLog(Tool.LogType.Operating, "增加客户信息" + customer.CustomerId, "增加成功"); ToolCode.Tool.ResetControl(this.Controls); return; } else { Tool.WriteLog(Tool.LogType.Operating, "增加客户信息" + customer.CustomerId, "增加失败!原因" + error); return; } } else { result = CustomerInfoManager.EditCustomer(customer, ref error); lbSubmit.Text = result == true ? "修改成功" : "修改失败!原因" + error; if (result) { Tool.WriteLog(Tool.LogType.Operating, "修改客户信息" + customer.CustomerId, "修改成功"); return; } else { Tool.WriteLog(Tool.LogType.Operating, "修改客户信息" + customer.CustomerId, "修改失败!原因" + error); return; } } }
private void FixupCustomer(Customer previousValue) { if (IsDeserializing) { return; } if (previousValue != null && previousValue.Orders.Contains(this)) { previousValue.Orders.Remove(this); } if (Customer != null) { if (!Customer.Orders.Contains(this)) { Customer.Orders.Add(this); } CustomerID = Customer.ID; } if (ChangeTracker.ChangeTrackingEnabled) { if (ChangeTracker.OriginalValues.ContainsKey("Customer") && (ChangeTracker.OriginalValues["Customer"] == Customer)) { ChangeTracker.OriginalValues.Remove("Customer"); } else { ChangeTracker.RecordOriginalValue("Customer", previousValue); } if (Customer != null && !Customer.ChangeTracker.ChangeTrackingEnabled) { Customer.StartTracking(); } } }