public ActionResult Update(int id, ProjectUpdate model) { if (!ModelState.IsValid) { var employeeList = new EmployeeRepo(); var customerList = new CustomerRepo(); model.Customers = customerList.GetCustomers(); model.Employees = employeeList.GetEmployees(); return(View(model)); } if (model.ProjectId != id) { ModelState.AddModelError("", "Id Mismatch"); return(View(model)); } var service = CreateProjectService(); if (service.UpdateProject(model)) { TempData["SaveResult"] = "The project has been updated."; return(RedirectToAction("Index")); } ModelState.AddModelError("", "Could not update the project."); return(View(model)); }
/// <summary> /// Default page for customers that returns the index view and /// is able to search through the customers by name/username /// </summary> /// <param name="firstName"></param> /// <param name="lastName"></param> /// <param name="userName"></param> /// <returns></returns> public async Task <IActionResult> Index(string firstName, string lastName, string userName) { var query = new CustomerRepo(); try { var customers = query.GetCustomers(_context); if (!String.IsNullOrEmpty(firstName)) { customers = query.SearchFirstName(customers, firstName); } if (!String.IsNullOrEmpty(lastName)) { customers = query.SearchLastName(customers, lastName); } if (!String.IsNullOrEmpty(userName)) { customers = query.SearchUserName(customers, userName); } return(View(await customers.ToListAsync())); } catch (Exception ex) { _logger.LogInformation(ex, "Wasn't able to search through customers."); } return(RedirectToAction(nameof(Index))); }
private void btnSave_Click(object sender, EventArgs e) { if (!ValidateForm()) { lblError.Visible = true; lblError.Text = "Please fill out all customer data."; return; } if (Mode == DetailMode.Add) { var address = ConstructAddress(); var addressId = AddressRepo.SaveAddress(address); var customer = ConstructCustomer(addressId); CustomerRepo.SaveCustomer(customer); } else if (Mode == DetailMode.Modify) { var address = ConstructAddress(); AddressRepo.UpdateAddress(address); var customer = ConstructCustomer(address.Id); CustomerRepo.UpdateCustomer(customer); } Dashboard.BindGrids(); Close(); }
public static async Task <IActionResult> DeleteCustomerById([HttpTrigger(AuthorizationLevel.Function, "delete", Route = "customers/{id}")] HttpRequest req, string id, ILogger log) { var customerRepo = new CustomerRepo(new ConnectionString()); customerRepo.Delete(int.Parse(id)); return(new OkObjectResult("ok")); }
public IActionResult CustomerView(string searchString) { CustomerVM CustomerResult = CustomerRepo.GetSentMessageByUser(searchString); return(View("Result", CustomerResult)); }
public ActionResult Create(Customer customer) { try { if (ModelState.IsValid) { Lib.Location libStore = StoreRepo.GetAllStores().First(); CustomerRepo.AddCustomer(new Lib.Customer { FirstName = customer.FirstName, LastName = customer.LastName, Birthday = customer.Birthday, StoreId = libStore.LocationId }); CustomerRepo.Save(); return(RedirectToAction(nameof(Index))); } return(View(customer)); } catch { return(View()); } }
public async Task <ActionResult> CreateLocation(CreateLocationViewModel model) { var locationRepository = new LocationRepo(); var orderRepository = new OrderRepo(); var customerRepository = new CustomerRepo(); var userId = User.Identity.GetUserId(); var location = new Models.Location { Title = model.Title, SecondTitle = model.SecondTitle, Customer = model.Customer, }; var order = new Order { LocationId = location.LocationId, UserId = userId }; location.UsersId.Add(userId); var testCustIds = await customerRepository.GetAllAsync(); await locationRepository.AddAsync(location); await orderRepository.AddAsync(order); return(RedirectToAction("Index", "Home", new { area = "" })); }
static void Main(string[] args) { Database.SetInitializer(new DataInitializer()); Console.WriteLine("***** Fun with ADO.NET EF Code First *****\n"); // adding inventory var car1 = new Inventory() { Make = "Yugo", Color = "Brown", PetName = "Brownie" }; var car2 = new Inventory() { Make = "SmartCar", Color = "Brown", PetName = "Shorty" }; AddNewRecord(car1); AddNewRecord(car2); AddNewRecords(new List<Inventory> { car1, car2 }); UpdateRecord(car1.CarId); ShowAllOrdersEagerlyFetched(); PrintAllInventory(); Console.WriteLine("***** Fun with ADO.NET EF Code First *****\n"); PrintAllCustomersAndCreditRisks(); var customerRepo = new CustomerRepo(); var customer = customerRepo.GetOne(4); customerRepo.Context.Entry(customer).State = EntityState.Detached; var risk = MakeCustomerARisk(customer); PrintAllCustomersAndCreditRisks(); Console.ReadLine(); }
public HomeController() { _doctorRepo = new DoctorRepo(); _customerRepo = new CustomerRepo(); context = new ApplicationDbContext(); databaseContext = new DatabaseContext(); }
private async Task GetCustomers() { var pagingResponse = await CustomerRepo.GetCustomers(_requestParams); CustomerList = pagingResponse.Items; MetaData = pagingResponse.MetaData; }
public ActionResult Create(ProjectCreate model) { if (!ModelState.IsValid) { var employeeList = new EmployeeRepo(); var customerList = new CustomerRepo(); model.Customers = customerList.GetCustomers(); model.Employees = employeeList.GetEmployees(); return(View(model)); } var service = CreateProjectService(); if (service.CreateProject(model)) { TempData["SaveResult"] = "Project successfully created!"; return(RedirectToAction("Index")); } ; ModelState.AddModelError("", "Project could not be created."); return(View(model)); }
protected void gvOrders_RowDataBound(object sender, GridViewRowEventArgs e) { Order order = (Order)e.Row.DataItem; if (order != null) { OrderStatu orderStatus = new OrderStatusRepo().GetById(ToSQL.SQLToInt(order.OrderStatus_ID)); if (orderStatus != null) { e.Row.Cells[2].Text = orderStatus.Name;//order stat } Customer customer = new CustomerRepo().GetById(ToSQL.SQLToInt(order.Customer_ID)); if (customer != null) { e.Row.Cells[3].Text = customer.FirstName;//customer nam } Model.Payment payment = new PaymentRepo().GetById(ToSQL.SQLToInt(order.Payment_ID)); if (payment != null) { e.Row.Cells[4].Text = payment.Name;//payment method } ShippingAddress shippingAddress = new ShippingAddressRepo().GetById(ToSQL.SQLToInt(order.ShippingAddress_ID)); if (shippingAddress != null) { e.Row.Cells[5].Text = shippingAddress.Name;//Recipient's Name e.Row.Cells[6].Text = shippingAddress.Phone; string strAddress = new AddressRepo().GetToString(shippingAddress.Address); e.Row.Cells[7].Text = new AddressRepo().ShortString(strAddress); e.Row.Cells[7].ToolTip = strAddress; } } }
public void GetCustomersByID_Valid() { #region ASSIGN CustomerRepo testRepo = new CustomerRepo(); CustomersApiController testController = new CustomersApiController(testRepo); #endregion #region ACT var taskReturn = testController.GetCustomer(1); taskReturn.Wait(); var result = taskReturn.Result.Value; Customer testData = result; #endregion #region ASSERT Assert.AreEqual(testData.Id, 1); Assert.AreEqual(testData.Name, "John Doe"); Assert.AreEqual(testData.UserName, "*****@*****.**"); Assert.AreEqual(testData.Street, "123 A Street"); Assert.AreEqual(testData.City, "Here"); Assert.AreEqual(testData.StateID, 1); Assert.AreEqual(testData.ZipCode, 10000); #endregion }
public HomeController() { cs = new CustomerRepo(); pr = new ProductRepo(); cr = new CartRepo(); cp = new ContactRepo(); }
// GET: Customer public ActionResult Index(string searchString) { ViewData["CurrentFilter"] = searchString; IEnumerable <P1B.Customer> customers = CustomerRepo.GetAllCustomers(); IEnumerable <P1B.Location> locations = LocRepo.GetAllLocations(); if (!String.IsNullOrEmpty(searchString)) { customers = customers.Where(c => c.FirstName.ToUpper().Contains(searchString.ToUpper()) || c.LastName.ToUpper().Contains(searchString.ToUpper())); } var viewModels = customers.Select(c => new CustomerViewModel { CustomerId = c.Id, FirstName = c.FirstName, LastName = c.LastName, DefaultLocation = c.DefaultLocation ?? null, DefaultLocationName = c.DefaultLocation != null ? (locations.Single(l => l.Id == (c.DefaultLocation ?? 0))).Name : "(none)" }).ToList(); return(View(viewModels)); }
public CustomerDetails(Login l) { InitializeComponent(); CustomerTable.AutoGenerateColumns = false; cr = new CustomerRepo(); }
protected void Login(object sender, EventArgs e) { Customer customer = new CustomerRepo().GetCustomerByUsername(txtUsername.Text); if (customer != null) { string Password = Security.Encrypt(customer.Key, txtPassword.Text); if (customer.Password.Equals(Password)) { Session["Customer"] = customer; WelcomeCustomer(); Response.Redirect(Request.Url.PathAndQuery); } else { lbLogin.Text = "Username/password provided is incorrect!"; txtUsername.Attributes["value"] = ""; txtPassword.Attributes["value"] = ""; ModalPopupLogin.Show(); } } else { lbLogin.Text = "Username/password provided is incorrect!"; txtUsername.Attributes["value"] = ""; txtPassword.Attributes["value"] = ""; ModalPopupLogin.Show(); } }
protected void btnSave_Click(object sender, EventArgs e) { int id = Utils.CIntDef(Request.QueryString["id"], 0); _CustomerRepo = new CustomerRepo(); Customer item = _CustomerRepo.GetById(id); if (item != null) { item.Fullname = txtTen.Value; item.Address = txtDiachi.Value; item.Appcode = lbAppcode.Text; item.Appnumber = Utils.CIntDef(txtSoluong.Value, 0); item.IsActive = (ddlKichhoat.SelectedItem.Value == "1") ? true : false; _CustomerRepo.Update(item); } else { item = new Customer(); item.Fullname = txtTen.Value; item.Address = txtDiachi.Value; string appcode = CreateAppcode(); item.Appcode = appcode; item.Appnumber = Utils.CIntDef(txtSoluong.Value, 0); item.IsActive = (ddlKichhoat.SelectedItem.Value == "1") ? true : false; item.CreatedDate = DateTime.Now; _CustomerRepo.Create(item); } Response.Redirect("~/pages/customers.aspx"); }
public ManageCustomerForm(Login l) { InitializeComponent(); this.l = l; cr = new CustomerRepo(); lr = new LoginRepo(); }
// GET: Order/Details/5 public ActionResult Details(int id) { IEnumerable <P1B.Customer> customers = CustomerRepo.GetAllCustomers(); IEnumerable <P1B.Location> locations = LocRepo.GetAllLocations(); List <Project1.BLL.Cupcake> cupcakes = CupcakeRepo.GetAllCupcakes().OrderBy(c => c.Id).ToList(); List <Project1.BLL.OrderItem> orderItems = OrderItemRepo.GetOrderItems(id).ToList(); Project1.BLL.Order order = OrderRepo.GetOrder(id); var viewModel = new OrderViewModel { OrderId = id, LocationId = order.OrderLocation, LocationName = locations.Single(l => l.Id == order.OrderLocation).Name, CustomerId = order.OrderCustomer, CustomerName = customers.Single(c => c.Id == order.OrderCustomer).ReturnFullName(), OrderTime = order.OrderTime, Locations = LocRepo.GetAllLocations().ToList(), Customers = CustomerRepo.GetAllCustomers().ToList(), Cupcakes = cupcakes, OrderItems = orderItems, OrderTotal = OrderRepo.GetOrder(order.Id).GetTotalCost(OrderItemRepo.GetOrderItems(order.Id).ToList(), cupcakes.ToList()) }; // give the Create view values for its dropdown return(View(viewModel)); }
public ActionResult Mail(List <ViewMail> maillist) { Customer cs = new Customer(); var model = CustomerRepo.CustomerList(); MailMessage msg = new MailMessage(); //yeni bir mail nesnesi Oluşturuldu. msg.IsBodyHtml = true; //mail içeriğinde html etiketleri kullanılsın mı? foreach (var item in model) { msg.To.Add(item.Email); //Kime mail gönderilecek. } msg.From = new MailAddress("*****@*****.**", "İletişim ", System.Text.Encoding.UTF8); //mail kimden geliyor, hangi ifade görünsün? msg.Subject = "Günün Menüsü"; //mailin konus 7 foreach (var item in maillist) { msg.Body += "<h3>" + item.GonderilecekMail + "</h3><br>"; /*"<center><h1 style='color:blue'>Hello</h1><h3>" + DateTime.Now.ToString("dd-MM-yyyy") + "</h3><li>"; */ } msg.IsBodyHtml = true; SmtpClient smp = new SmtpClient(); smp.Credentials = new NetworkCredential("*****@*****.**", "hakan123."); //mailin gönderileceği adres ve kullanıcı adı,şifresi smp.Port = 587; smp.Host = "smtp.gmail.com"; //gmail üstrzerinden gönderiliyor. smp.EnableSsl = true; smp.Send(msg); //msg isimli mail gönderiliyor. return(RedirectToAction("Add", "Admin")); }
protected void btnSave_Click(object sender, EventArgs e) { CustomerRepo customerrepo = new CustomerRepo(); lbMessage.Text = ""; if (customerrepo.DoesUsernameExist(txtUserName.Text)) { lbMessage.Text = "Username already exists!"; lbMessage.ForeColor = System.Drawing.Color.Red; txtUserName.Text = ""; return; } if (customerrepo.DoesEmailExist(txtEmail.Text)) { lbMessage.Text = "Email already exists!"; lbMessage.ForeColor = System.Drawing.Color.Red; txtEmail.Text = ""; return; } Model.Customer customer = new Model.Customer(); customer.FirstName = txtFirstName.Text; customer.LastName = txtLastName.Text; customer.Username = txtUserName.Text; customer.Password = Security.Encrypt(ConfigurationManager.AppSettings["KeyCustomer"], txtPassword.Text); customer.Key = ConfigurationManager.AppSettings["KeyCustomer"]; customer.Email = txtEmail.Text; customer.Phone = txtPhone.Text; customer.DateOfBirth = ToSQL.SQLToDateTimeNull(txtDateOfBirth.Text); customer.Gender = rdbtnGender.SelectedIndex == 0 ? true : false; customer.DateCreated = DateTime.Now; int i = customerrepo.CreateCustomer(customer); Response.Redirect("Management-Customer.aspx"); }
// GET: Cart public ActionResult Index(int Id) { ViewBag.orderId = Id; Library.Order order = OrderRepo.GetOrderById(Id); IEnumerable <Lib.Inventory> libInv = StoreRepo.GetInventory(order.StoreId); IEnumerable <Lib.Product> libProducts = StoreRepo.GetInventoryProducts(libInv); IEnumerable <InventoryViewModel> ivm = libProducts.Select(x => new InventoryViewModel { Id = x.Id, Name = x.Name, Price = (decimal)x.Price, Quantity = libInv.First(i => i.ProductId == x.Id && i.StoreId == order.StoreId).Quantity, StoreName = StoreRepo.GetStoreById(order.StoreId).Name, CustomerName = CustomerRepo.GetCustomerById(order.CustomerId).FirstName + ' ' + CustomerRepo.GetCustomerById(order.CustomerId).LastName }); IEnumerable <Lib.OrderItems> libOrderItems = OrderRepo.GetOrderItems(order.Id); IEnumerable <Lib.Product> libOrderProducts = OrderRepo.GetOrderProducts(libOrderItems); IEnumerable <CartViewModel> cvm = libOrderProducts.Select(x => new CartViewModel { Name = x.Name, Price = (decimal)x.Price, Quantity = libOrderItems.First(i => i.ProductId == x.Id && i.OrderId == order.Id).Quantity, Ivm = ivm, Total = OrderRepo.OrderTotal(order.Id) }); return(View(cvm)); }
// GET: Order public ActionResult Index(int Id) { if (CustomerRepo.ContainsId(Id)) { ViewBag.customerId = Id; Library.Customer customer = CustomerRepo.GetCustomerById(Id); IEnumerable <Lib.Inventory> libInv = StoreRepo.GetInventory(customer.StoreId); IEnumerable <Lib.Product> libProducts = StoreRepo.GetInventoryProducts(libInv); IEnumerable <InventoryViewModel> ivm = libProducts.Select(x => new InventoryViewModel { Id = x.Id, Name = x.Name, Price = (decimal)x.Price, Quantity = libInv.First(i => i.ProductId == x.Id && i.StoreId == customer.StoreId).Quantity, StoreName = StoreRepo.GetStoreById(customer.StoreId).Name, CustomerName = customer.FirstName + ' ' + customer.LastName }); return(View(ivm)); } else { return(RedirectToAction("Index", "Home")); } }
public ActionResult AddOrder(int Id) { try { if (ModelState.IsValid) { Library.Customer customer = CustomerRepo.GetCustomerById(Id); OrderRepo.AddOrder(new Lib.Order { CustomerId = customer.Id, StoreId = customer.StoreId, TimePlaced = DateTime.Now }); var order = OrderRepo.GetAllOrders().Last(); var inv = StoreRepo.GetInventoryProducts(StoreRepo.GetInventory(customer.StoreId)); foreach (Lib.Product item in inv) { OrderRepo.AddProduct(order.Id, item); } return(RedirectToAction("Index", "Cart", new { @id = order.Id })); } } catch { return(RedirectToAction(nameof(Index))); } return(RedirectToAction(nameof(Index))); }
public Form1() { InitializeComponent(); Control.CheckForIllegalCrossThreadCalls = false; logCustomer = new CustomerRepo().Queryable().Count(); logMailLog = new MailLogRepo().Queryable().Count(); }
public CustomerTests() { _db = new RushHourContext(); _repo = new CustomerRepo(); CleanDatabase(); }
// GET: CustomerInformation/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } 客戶資料 客戶資料 = CustomerRepo.Find(id.Value); if (客戶資料 == null) { return(HttpNotFound()); } var items = (from p in classification select p.Key) .Distinct() .OrderBy(p => p) .Select(p => new SelectListItem() { Text = classification[p].ToString(), Value = p.ToString() }); ViewBag.客戶分類 = new SelectList(items, "Value", "Text", 客戶資料.客戶分類); return(View(客戶資料)); }
public ActionResult CustomerExcel(string sheetName, string fileName) { if (String.IsNullOrEmpty(sheetName)) { sheetName = "工作表1"; } if (String.IsNullOrEmpty(fileName)) { fileName = string.Concat(DateTime.Now.ToString("yyyyMMddHHmmss"), ".xlsx"); } var data = CustomerRepo.All().Select(p => new { p.客戶名稱, p.統一編號, p.電話, p.傳真, p.地址, p.Email }); var workbook = new XLWorkbook(); var MymemoryStream = new MemoryStream(); //設置默認Style var style = workbook.Style; style.Font.FontName = "Microsoft YaHei"; style.Font.FontSize = 16; var worksheet = workbook.Worksheets.Add(sheetName); worksheet.Cell(1, 1).Value = "客戶名稱"; worksheet.Cell(1, 2).Value = "統一編號"; worksheet.Cell(1, 3).Value = "電話"; worksheet.Cell(1, 4).Value = "傳真"; worksheet.Cell(1, 5).Value = "地址"; worksheet.Cell(1, 6).Value = "Email"; worksheet.Cell(2, 1).InsertData(data); workbook.SaveAs(MymemoryStream); return(File(MymemoryStream.ToArray(), "application/vnd.ms-excel", fileName)); }
// GET: Order/Create public ActionResult Create() { List <Project1.BLL.Cupcake> cupcakesTemp = CupcakeRepo.GetAllCupcakes().OrderBy(c => c.Id).ToList(); List <Project1.BLL.OrderItem> orderItemsTemp = new List <Project1.BLL.OrderItem>(); foreach (var cupcake in cupcakesTemp) { cupcake.Type = Regex.Replace(cupcake.Type, "([a-z])([A-Z])", "$1 $2"); orderItemsTemp.Add(new Project1.BLL.OrderItem { Id = 0, OrderId = 0, CupcakeId = cupcake.Id, Quantity = null }); } var viewModel = new OrderViewModel { Locations = LocRepo.GetAllLocations().ToList(), Customers = CustomerRepo.GetAllCustomers().ToList(), Cupcakes = cupcakesTemp, OrderItems = orderItemsTemp }; foreach (Project1.BLL.Customer customer in viewModel.Customers) { customer.FullName = customer.ReturnFullName(); } // give the Create view values for its dropdown return(View(viewModel)); }
static void Main(string[] args) { // Database.SetInitializer(new DataInitializer()); WriteLine("***Work with ADO.NET EF Code First\n"); // var car1 = new Inventory { Make = "Yogo", Color = "Brown", PetName = "Brownie" }; // var car2 = new Inventory { Make = "SamrtCar", Color = "Brown", PetName = "Smarty" }; // AddNewRecord(car1); // AddNewRecord(car2); // AddNewRecords(new List<Inventory> { car1, car2 }); // UpdateRecord(car1.CarId); // PrintAllInventory(); // ShowAllOrders(); // OrderRepo.ShowAllOrdersEagerlyFeched(); PrintAllCustomersAndCreditRisks(); var customerRepo = new CustomerRepo(); var customer = customerRepo.GetOne(1); customerRepo.Context.Entry(customer).State = EntityState.Detached; var risk = MakeCustomerARisk(customer); // PrintAllCustomersAndCreditRisks(); ReadLine(); }
private string CreateAppcode() { string appcode = Security.CreateAppcode(); _CustomerRepo = new CustomerRepo(); Customer item = _CustomerRepo.GetByAppcode(appcode); if (item != null) CreateAppcode(); return appcode; }
private void LoadInfo() { int id = Utils.CIntDef(Request.QueryString["id"], 0); _CustomerRepo = new CustomerRepo(); Customer item = _CustomerRepo.GetById(id); if (item != null) { lbTen.Text = item.Fullname; } }
protected void btnRemove_Click(object sender, EventArgs e) { if (!chkChacchan.Checked) { lbMessage.Text = "Bạn chưa đồng ý chắc chắn xóa!"; return; } int id = Utils.CIntDef(Request.QueryString["id"], 0); _CustomerRepo = new CustomerRepo(); _CustomerRepo.Remove(id); Response.Redirect("~/pages/customers.aspx"); }
private void LoadInfo() { int id = Utils.CIntDef(Request.QueryString["id"], 0); _CustomerRepo = new CustomerRepo(); Customer item = _CustomerRepo.GetById(id); if (item != null) { txtTen.Value = item.Fullname; txtDiachi.Value = item.Address; lbAppcode.Text = item.Appcode; txtSoluong.Value = Utils.CStrDef(item.Appnumber, ""); ddlKichhoat.SelectedIndex = Utils.CBoolDef(item.IsActive, false) ? 0 : 1; } }
private void LoadData() { _CustomerRepo = new CustomerRepo(); rptList.DataSource = _CustomerRepo.GetAll(); rptList.DataBind(); }