public async Task TestCustAdd() { CustomerDAL Repo; var conn = new SqliteConnection("DataSource=:memory:"); conn.Open(); try { var options = new DbContextOptionsBuilder <WheyMenContext>() .UseSqlite(conn) .Options; using (var context = new WheyMenContext(options)) { context.Database.EnsureCreated(); } using (var context = new WheyMenContext(options)) { Repo = new CustomerDAL(context); var custs = await Repo.GetCusts(); int initial_count = custs.ToList().Count; Customer cust1 = new Customer { Name = "jon", LastName = "alt", Pwd = "abc", Email = "*****@*****.**", Username = "******" }; Customer cust2 = new Customer { Name = "jon", LastName = "alt", Pwd = "abc", Email = "*****@*****.**", Username = "******" }; Customer cust3 = new Customer { Name = "jon", LastName = "alt", Pwd = "abc", Email = "*****@*****.**", Username = "******" }; int x = Repo.Add(cust1); int y = Repo.Add(cust2); int z = Repo.Add(cust3); custs = await Repo.GetCusts(); int final_count = custs.ToList().Count; Assert.IsTrue(final_count == (initial_count + 3)); Repo.Remove(x); Repo.Remove(y); Repo.Remove(z); } } finally { conn.Close(); } }
public IHttpActionResult Post() { AjaxStringResult result = new AjaxStringResult(); Customer model = new Customer(); JObject obj = new JObject(); var form = HttpContext.Current.Request.Form; foreach (var key in form.AllKeys) { obj[key] = form[key]; } model = obj.ToObject <Customer>(); if (model != null) { model.CreateTime = DateTime.Now; HttpFileCollection filelist = HttpContext.Current.Request.Files; if (filelist != null && filelist.Count > 0) { string filePath = CommonHelper.GetMapPath(filelist[0].FileName); filelist[0].SaveAs(filePath); model.Contract = Path.GetFileName(filePath); } _CustomerDAL.Add(model); result.data = "保存成功"; } return(Json(result)); }
public ActionResult Index(Register register) { if (ModelState.IsValid) { //Add customer record to database register.CustomerID = CustomerContext.Add(register); TempData["Message"] = "Your Account have been successfully created!"; return(RedirectToAction("Index")); } else { //Input validation fails, return to the register view to display error message return(View(register)); } }
public async Task TestCustDelete() { CustomerDAL Repo; var conn = new SqliteConnection("DataSource=:memory:"); conn.Open(); try { var options = new DbContextOptionsBuilder <WheyMenContext>() .UseSqlite(conn) .Options; using (var context = new WheyMenContext(options)) { context.Database.EnsureCreated(); } using (var context = new WheyMenContext(options)) { Repo = new CustomerDAL(context); var custs = await Repo.GetCusts(); int initialCount = custs.ToList().Count; var newCust = new Customer { Email = "*****@*****.**", Name = "asd", LastName = "dasd", Pwd = "asda", Username = "******" }; int addedID = Repo.Add(newCust); Repo.Remove(addedID); custs = await Repo.GetCusts(); int finalCount = custs.ToList().Count; Assert.AreEqual(initialCount, finalCount); } } finally { conn.Close(); } }
public bool SaveEntities(Customer customer) { if (customer.KeyId == 0) { if (customerDAL.Add(customer) != null) { return(true); } return(false); } else { if (customerDAL.Update(customer) != null) { return(true); } return(false); } }
public void TestSetup(WheyMenContext context) { OrderDAL Repo; LocationDAL LocDal; CustomerDAL CustDal; Repo = new OrderDAL(context); LocDal = new LocationDAL(context); CustDal = new CustomerDAL(context); var cust = new Customer { Id = 1, Name = "jon", LastName = "asd", Email = "*****@*****.**", Username = "******", Pwd = "asd" }; var loc = new Loc { Id = 1, Name = "gnc", }; var prod = new Products { Id = 1, Price = 12, Name = "wpi", }; var inventory = new Inventory { Id = 5, Qty = 10000, Pid = 1, StoreId = 1 }; CustDal.Add(cust); LocDal.Add(loc); context.Products.Add(prod); context.Inventory.Add(inventory); context.SaveChanges(); }
public ActionResult Create(Customer customer) { //Get country list for drop-down list //in case of the need to return to Create.cshtml view ViewData["CountryList"] = GetCountries(); if (ModelState.IsValid) { //Add staff record to database customer.CustomerID = customerContext.Add(customer); //Redirect user to Staff/Index view return(RedirectToAction("Index")); } else { //Input validation fails, return to the Create view //to display error message return(View(customer)); } }
public void TestCustEdit() { CustomerDAL Repo; var conn = new SqliteConnection("DataSource=:memory:"); conn.Open(); try { var options = new DbContextOptionsBuilder <WheyMenContext>() .UseSqlite(conn) .Options; using (var context = new WheyMenContext(options)) { context.Database.EnsureCreated(); } using (var context = new WheyMenContext(options)) { Repo = new CustomerDAL(context); Customer cust1 = new Customer { Name = "jon", LastName = "alt", Pwd = "abc", Email = "*****@*****.**", Username = "******" }; int target = Repo.Add(cust1); var toEdit = Repo.FindByID(target); toEdit.Name = "Bren"; Repo.Edit(toEdit); var editedCust = Repo.FindByID(target); Assert.AreEqual("Bren", editedCust.Name); editedCust.Name = "Jon"; Repo.Edit(editedCust); } } finally { conn.Close(); } }
public ActionResult BookAirTicket(Aircraftschedule booking) { //Get country list for drop-down list //in case of the need to return to index.cshtml view ViewData["CountryList"] = GetCountries(); if (ModelState.IsValid) { //Add customer record to database int customerid = (int)HttpContext.Session.GetInt32("id"); CustomerContext.Add(booking); TempData["Newbooking"] = "New Booking have been successfully created!"; return(RedirectToAction("ViewAirTicket")); } else { //Input validation fails, return to the register view to display error message return(View(booking)); } }
/// <summary> /// 添加对象 /// </summary> /// <param name="info"></param> /// <returns>自增主键</returns> public long InsertInfo(CustomerInfo info) { int cnt = dal.GetCounts("[CUST_CODE] = N'" + info.CustCode + "'"); if (cnt > 0) { throw new Exception("MC:0x00000081");///客户代码不允许重复 } cnt = dal.GetCounts("[CUST_NAME] = N'" + info.CustName + "'"); if (cnt > 0) { throw new Exception("MC:0x00000082");///客户名称不允许重复 } cnt = dal.GetCounts("[CUST_NICKNAME] = N'" + info.CustNickname + "'"); if (cnt > 0) { throw new Exception("MC:0x00000083");///客户简称不允许重复 } return(dal.Add(info)); }
public ActionResult SignUp(Customer customer) { List <Customer> existingCustomers = customerContext.GetAllCustomers(); if (ModelState.IsValid) { foreach (Customer c in existingCustomers) { if (customer.EmailAddr == c.EmailAddr) { TempData["Message"] = "This account already exists."; return(RedirectToAction("SignUp")); } } customerContext.Add(customer); return(RedirectToAction("Login", "Home")); } else { return(View(customer)); } }
public Customer AddCustomers(Customer model) { return(dal.Add(model)); }