Product IProductService.Find(int ProductID) { using (var context = new DataBaseEntities(DBManager.EntityConnectionString)) { return(context.Products.Where(i => i.ProductID == ProductID).First()); } }
/// <summary> /// Возвращает количество клиентов до указаного ID /// </summary> /// <param name="predicate">Фильтрация</param> /// <param name="ID"></param> /// <returns></returns> public int Count(Func <Client, bool> predicate, int ID) { using (DataBaseEntities db = new DataBaseEntities()) { return(db.Client.Where(predicate).OrderBy(c => c.ID).Count(c => c.ID <= ID)); } }
public async Task <IHttpActionResult> PasswordReset([FromBody] TD_Login model) { if (!UtilityHelper.VerifyMobileCode(model.Mobile, model.Code, true)) { return(Json(new { Code = 1, Message = "验证码错误或已经失效" })); } DataBaseEntities db = new DataBaseEntities(); var user = db.AspNetUsers.SingleOrDefault(u => u.MyMobilePhone == model.Mobile); if (user == null) { return(Json(new { Code = 1, Message = "没有该手机号码" })); } string resetToken = await UserManager.GeneratePasswordResetTokenAsync(user.Id); IdentityResult passwordChangeResult = await UserManager.ResetPasswordAsync(user.Id, resetToken, model.Password); if (!passwordChangeResult.Succeeded) { return(Json(new { Code = 1, Message = "修改密码错误" })); } return(Json(new { Code = 10000, Detail = true })); }
private void Fill_data(int ID) { using (DataBaseEntities db = new DataBaseEntities()) { bindingSourceClient.Add(db.Client.FirstOrDefault(c => c.ID == ID)); client = ((ModelDB.Client)bindingSourceClient[0]); switch (client.Gender.Name) { case "Мужской": rbtn_male.Checked = true; break; default: rbtn_female.Checked = true; break; } string photoPath = Environment.CurrentDirectory + @"\" + client.PhotoPath; if (File.Exists(photoPath)) { img_photo.Image = new Bitmap(photoPath); } } Fill_listTag(); }
IEnumerable <OrderLine> IOrderService.OrderDetails(int OrderID) { using (var context = new DataBaseEntities(DBManager.EntityConnectionString)) { return(context.Orders.First(i => i.OrderID == OrderID).OrderLines.ToList()); } }
private void Delete_client() { if (MessageBox.Show("Вы дейтсвительно хотите удалить запись?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk) == DialogResult.Yes) { using (DataBaseEntities db = new DataBaseEntities()) { int ID = (int)dgv_client[0, dgv_client.SelectedRows[0].Index].Value; var client = db.Client.FirstOrDefault(c => c.ID == ID); if (client.VisitInfo.Count > 0) { MessageBox.Show("Невозможно удалить запись, так как есть данные о посещении."); } else { db.Client.Remove(client); if (client.TagOfClient.Select(t => t.Tag).ToList().Count > 0) { foreach (var tag in client.TagOfClient.Select(t => t.Tag).ToList()) { db.Tag.Remove(tag); } } db.SaveChanges(); UpdateData(); } } } }
Invoice IInvoiceService.Find(int InvoiceID) { using (var context = new DataBaseEntities(DBManager.EntityConnectionString)) { return(context.Invoices.Where(i => i.InvoiceID == InvoiceID).First()); } }
// GET: Home public ActionResult Index() { DataBaseEntities db = new DataBaseEntities(); var users = db.Users; return(View(users)); }
/// <summary> /// Возвращает количество клиентов /// </summary> public int Count() { using (DataBaseEntities db = new DataBaseEntities()) { return(db.Client.Count()); } }
IEnumerable <Product> IProductService.GetAll() { using (var context = new DataBaseEntities(DBManager.EntityConnectionString)) { return(context.Products.ToList()); } }
Order IOrderService.Find(int OrderID) { using (var context = new DataBaseEntities(DBManager.EntityConnectionString)) { return(context.Orders.First(i => i.OrderID == OrderID)); } }
Device IDeviceService.Find(int DeviceId) { using (var context = new DataBaseEntities(DBManager.EntityConnectionString)) { return(context.Devices.First(i => i.DeviceID == DeviceId)); } }
IEnumerable <Device> IDeviceService.FindByCustomer(int customerId) { using (var context = new DataBaseEntities(DBManager.EntityConnectionString)) { return(context.Devices.Where(i => i.CustomerID == customerId).ToList()); } }
void IOrderService.Delete(int OrderID) { using (var context = new DataBaseEntities(DBManager.EntityConnectionString)) { Order oldOrder = context.Orders.Where(i => i.OrderID == OrderID).First(); context.DeleteObject(oldOrder); context.SaveChanges(); } }
void IOrderService.Update(Order Order) { using (var context = new DataBaseEntities(DBManager.EntityConnectionString)) { Order oldOrder = context.Orders.Where(i => i.OrderID == Order.OrderID).First(); oldOrder = Order; context.SaveChanges(); } }
int IOrderService.Add(Order Order) { using (var context = new DataBaseEntities(DBManager.EntityConnectionString)) { context.Orders.AddObject(Order); context.SaveChanges(); return(Order.OrderID); } }
void IProductService.Delete(int ProductID) { using (var context = new DataBaseEntities(DBManager.EntityConnectionString)) { Product oldProduct = context.Products.Where(i => i.ProductID == ProductID).First(); context.DeleteObject(oldProduct); context.SaveChanges(); } }
int IProductService.Add(Product Product) { using (var context = new DataBaseEntities(DBManager.EntityConnectionString)) { context.Products.AddObject(Product); context.SaveChanges(); return(Product.ProductID); } }
void IDeviceService.Delete(int DeviceId) { using (var context = new DataBaseEntities(DBManager.EntityConnectionString)) { Device oldDevice = context.Devices.Where(i => i.DeviceID == DeviceId).First(); context.DeleteObject(oldDevice); context.SaveChanges(); } }
void IDeviceService.Update(Device Device) { using (var context = new DataBaseEntities(DBManager.EntityConnectionString)) { Device oldDevice = context.Devices.Where(i => i.DeviceID == Device.DeviceID).First(); oldDevice = Device; context.SaveChanges(); } }
int IDeviceService.Add(Device Device) { using (var context = new DataBaseEntities(DBManager.EntityConnectionString)) { context.Devices.AddObject(Device); context.SaveChanges(); return(Device.DeviceID); } }
void IInvoiceService.Update(Invoice Invoice) { using (var context = new DataBaseEntities(DBManager.EntityConnectionString)) { Invoice oldInvoice = context.Invoices.Where(i => i.InvoiceID == Invoice.InvoiceID).First(); oldInvoice = Invoice; context.SaveChanges(); } }
private void btn_showBirthDay_Click(object sender, EventArgs e) { using (DataBaseEntities db = new DataBaseEntities()) { filter = c => c.Birthday.Value.Month == DateTime.Now.Month; } UpdateData(); }
private void Fill_gender() { using (DataBaseEntities db = new DataBaseEntities()) { genders = db.Gender.AsNoTracking().ToList(); rbtn_female.Tag = genders.FirstOrDefault(g => g.Name == "Женский"); rbtn_male.Tag = genders.FirstOrDefault(g => g.Name == "Мужской"); } }
public VisitInfo(int ID) { InitializeComponent(); using (DataBaseEntities db = new DataBaseEntities()) { ClientService clientService = db.ClientService.FirstOrDefault(s => s.ID == ID); lbl_nameService.Text = clientService.Service.Title; lbl_date.Text = clientService.StartTime.ToString("yyyy.mm.dd hh:mm"); lbl_countFile.Text = "Всего файлов: " + clientService.DocumentByService.Count(); } }
public VisitsInfoOfClient(int ClientID) { InitializeComponent(); using (DataBaseEntities db = new DataBaseEntities()) { foreach (var item in db.ClientService.Where(c => c.ClientID == ClientID)) { SchoolsLanguage.UserControls.VisitInfo visitInfo = new UserControls.VisitInfo(item.ID); container.Controls.Add(visitInfo); } } }
IEnumerable <Customer> ICustomerService.GetAll() { using (var context = new DataBaseEntities()) { try { return(context.Customers.ToList()); } catch (Exception) { throw new FaultException("Failed to get Customers"); } } }
public Client() { InitializeComponent(); Fill_gender(); client = new ModelDB.Client(); bindingSourceClient.Add(client); using (DataBaseEntities db = new DataBaseEntities()) { client.ID = db.Client.ToList().OrderByDescending(c => c.ID).First().ID + 1; } btn_showVisitInfo.Visible = false; }
void IProductService.Update(Product Product) { using (var context = new DataBaseEntities(DBManager.EntityConnectionString)) { Product oldProduct = context.Products.Where(i => i.ProductID == Product.ProductID).First(); oldProduct.isDiscontinued = Product.isDiscontinued; oldProduct.ProductCode = Product.ProductCode; oldProduct.ProductGroup = Product.ProductGroup; oldProduct.ProductName = Product.ProductName; oldProduct.ProductPrice = Product.ProductPrice; context.SaveChanges(); } }
void ICustomerService.Update(Customer Customer) { using (var context = new DataBaseEntities()) { try { context.Customers.Attach(Customer); context.ObjectStateManager.ChangeObjectState(Customer, EntityState.Modified); context.SaveChanges(); } catch (Exception) { throw new FaultException("Error updating customer id#" + Customer.CustomerID); } } }