public void RegisterUser(RegisterUserVM user) { var user1 = Mapper.Map <User>(user); Contex.Users.Add(user1); Contex.SaveChanges(); }
public static Client CheckedClient(Client client, string firstname, string lastname, string secondname, string phonenumber) { Contex My = new Contex(); try { if (client.FirstName.Equals(firstname)) { if (client.LastName.Equals(lastname)) { if (client.SecondName.Equals(secondname)) { if (client.PhoneNumber.Equals(phonenumber)) { return(client); } } } } return(null); } catch { return(null); } }
public string Autorisation(string login, string password) { Contex My = new Contex(); try { Employee employee = My.Employees.Where(s => s.Login == login).FirstOrDefault(); int RoleId = employee.RoleId; Role role = My.Roles.FirstOrDefault(b => b.RoleId == RoleId); if (employee.Password.Equals(password)) { if (role.Name == "Директор") { return("admin"); } return("user"); } else { return(null); } } catch { return(null); } }
public void AddUser(AddUserBM user) { var userToAdd = Mapper.Map <User>(user); Contex.Users.Add(userToAdd); Contex.SaveChanges(); }
public static bool Modificar(NotasCredito nota) { bool paso = false; try { Contex contex = new Contex(); var estudiante = BLL.EstudiantesBLL.Buscar(nota.EstudianteID); var notas = Buscar(nota.NotasID); estudiante.Monto -= notas.Monto; BLL.EstudiantesBLL.Modificar(estudiante); contex.Entry(nota).State = EntityState.Modified; estudiante.Monto += nota.Monto; BLL.EstudiantesBLL.Modificar(estudiante); if (contex.SaveChanges() > 0) { paso = true; } } catch (Exception) { throw; } return(paso); }
public void Logout(string sessionId) { var session = Contex.Sessions.FirstOrDefault(x => x.SessionId == sessionId); session.IsActive = false; Contex.SaveChanges(); }
public void AddSupplier(AddSupplierVM supplier, int userId) { var newSupp = Mapper.Map <Supplier>(supplier); Contex.Suppliers.Add(newSupp); Contex.SaveChanges(); this.AddLog(userId, Operation.Add); }
public void AddCar(AddCarBM car, User user) { var carToAdd = Mapper.Map <AddCarBM, Car>(car); Contex.Cars.Add(carToAdd); Contex.SaveChanges(); this.AddLog(user, Operation.Add, "Car"); }
public void Addpart(AddPartVM part) { var partToAdd = Mapper.Map <AddPartVM, Part>(part); var supplier = Contex.Suppliers.Find(partToAdd.Supplier.Id); // supplier.Parts.Add(partToAdd); Contex.Parts.Add(partToAdd); Contex.SaveChanges(); }
public void SignOutStudentFromCourse(string courseName, string currentUser) { var course = Contex.Courses.FirstOrDefault(x => x.Name == courseName); var student = Contex.Students.FirstOrDefault(x => x.User.Email == currentUser); course.Students.Remove(student); student.Courses.Remove(course); Contex.SaveChanges(); }
public void EditSupplier(EditSupplierBM model, int userId) { var supplier = Mapper.Map <Supplier>(model); Contex.Entry(supplier).State = EntityState.Modified; Contex.SaveChanges(); this.AddLog(userId, Operation.Edit); }
public void Add(AddCameraVM model, User user) { var camera = Mapper.Map <Models.Entity.Camera>(model); camera.User = user; Contex.Cameras.Add(camera); Contex.SaveChanges(); }
public void RegisterStudent(ApplicationUser user) { var student = new Student(); var currentUser = Contex.Users.Find(user.Id); student.User = currentUser; Contex.Students.Add(student); Contex.SaveChanges(); }
public void AddNewCategory(AddNewCategoryBindingModel model) { if (!Contex.Categories.Any(x => x.Name == model.Name)) { var category = new Category(); category.Name = model.Name; category.Topics = new List <Topic>(); Contex.Categories.Add(category); Contex.SaveChanges(); } }
private void ButtonShowProperty_Click(object sender, RoutedEventArgs e) { if (TextBoxRfid.Text == string.Empty) { MessageBox.Show("ثبت کارت ناموفق بوده است لطفا دوباره کارت را روی دستگاه کارت خوان قرار دهید"); TextBoxRfid.Focus(); return; } try { // var entityConnectionString = Contex.BuildEntityConnection(@"Data Source=192.168.0.17\sql2014;Initial Catalog=Personel;User ID=sa;Password=@110;Connection Timeout=60;"); //string entityConnectionString="Data Source=192.168.0.17\\sql2014;Initial Catalog=Personel;User ID=sa;Password=@110;Connection Timeout=60;"; var setting = GetSetting(); var entityConnectionString = Contex.BuildEntityConnection(setting.DataSource, setting.Instance, setting.InitialCatalog, setting.UserId, setting.Password); using (var dbs = new WpfManage.DAL.Contex()) { var s = dbs.memberMap.Where(x => x.RfidCard == TextBoxRfid.Text).FirstOrDefault(); if (TextBoxRfid.Text == s.RfidCard) { TextBlockFullName.Text = s.FullName; TextBlockNCode.Text = s.NCode; TextBlockNameFather.Text = s.NameFather; TextBlockNoPersonel.Text = s.PersonelNumber; TextBlockTellephone.Text = s.Tellephone; TextBlockAddress.Text = s.Address; // TextBoxRfId.Text = s.Image; byte[] binaryData = Convert.FromBase64String(s.Image); BitmapImage bi = new BitmapImage(); bi.BeginInit(); bi.StreamSource = new MemoryStream(binaryData); bi.EndInit(); ImagePersonel.Source = bi; ImagePlay.Visibility = Visibility.Hidden; // TextBoxRfid.Focus(); // TextBoxRfid.Clear(); // dbs.ProjectmemberMap.Add(s); } } } catch (Exception exception) { // MessageBox.Show("خطا در ارتباط"); } // TextBoxRfid.Clear(); }
private void AddLog(User user, Operation operation, string modifiedTable) { Log log = new Log() { User = user, DateModified = DateTime.Now, ModifiedTable = modifiedTable, Operation = operation }; Contex.Logs.Add(log); Contex.SaveChanges(); }
public void Create(CreateVM model) { var course = new Course() { Description = model.Description, Name = model.Name, StartDate = model.StartDate, EndDate = model.EndDate }; Contex.Courses.Add(course); Contex.SaveChanges(); }
public void AddLog(int userId, Operation operation) { User user = Contex.Users.Find(userId); Log log = new Log() { User = user, DateModified = DateTime.Now, ModifiedTable = "Suppliers", Operation = operation }; Contex.Logs.Add(log); Contex.SaveChanges(); }
public static List <NotasCredito> GetList(Expression <Func <NotasCredito, bool> > criterioBusqueda) { List <NotasCredito> NotaCredito = new List <NotasCredito>(); try { Contex contex = new Contex(); NotaCredito = contex.Notas.Where(criterioBusqueda).ToList(); } catch (Exception) { throw; } return(NotaCredito); }
public static NotasCredito Buscar(int EstudianteId) { NotasCredito NotaCredito = new NotasCredito(); try { Contex contex = new Contex(); NotaCredito = contex.Notas.Find(EstudianteId); } catch (Exception) { throw; } return(NotaCredito); }
public void AddSale(AddSaleConfirmationBM sale) { var customer = Contex.Customers.FirstOrDefault(x => x.Name == sale.Customer); var carData = sale.Car.Split(); var carMake = carData[0]; var carModel = carData[1]; var car = Contex.Cars.FirstOrDefault(x => x.Make == carMake && x.Model == carModel); Contex.Sales.Add(new Sale() { Customer = customer, Car = car, Discount = sale.Discount }); Contex.SaveChanges(); }
public void AddCustomer(AddCustomerBM customerBM) { var customer = Mapper.Map <AddCustomerBM, Customer>(customerBM); var age = DateTime.Today.Year - customerBM.BirthDate.Year; if (age > 18) { customer.IsYoungDriver = false; } else { customer.IsYoungDriver = true; } Contex.Customers.Add(customer); Contex.SaveChanges(); }
public void EditCustomer(EditCustomerBM customerBM) { var customer = Contex.Customers.Find(customerBM.Id); var age = DateTime.Today.Year - customerBM.BirthDate.Year; if (age > 18) { customer.IsYoungDriver = false; } else { customer.IsYoungDriver = true; } customer.Name = customerBM.Name; customer.BirthDate = customerBM.BirthDate; Contex.Entry(customer).State = EntityState.Modified; Contex.SaveChanges(); }
private static bool Ceckdbstatus() { //اگر ساخته شد متد دیتابیس // var entityConnectionString = Contex.BuildEntityConnection (@"Data Source=192.168.0.17\sql2014;Initial Catalog=Personel;User ID=sa;Password=@110;Connection Timeout=60;"); var setting = GetSetting(); var entityConnectionString = Contex.BuildEntityConnection(setting.DataSource, setting.Instance, setting.InitialCatalog, setting.UserId, setting.Password); using (var db = new Contex()) { if (db.Database.Exists()) { return(true); } else { return(false); } } }
private void MethodFillGrid() { //متذ پر کردن گرید try { var setting = GetSetting(); var entityConnectionString = Contex.BuildEntityConnection(setting.DataSource, setting.Instance, setting.InitialCatalog, setting.UserId, setting.Password); using (var dbs = new Contex()) { var result = (from r in dbs.memberMap.ToList() select r).ToList(); DataGridPersonel.ItemsSource = result; //if (dbs.Database.Exists()) //{ //var blog = new Personel { FullName = "Razeghi" }; //dbs.memberMap.Add(blog); //dbs.SaveChanges(); // MessageBox.Show(dbs.Database.Connection.ConnectionString); // string s = dbs.Database.Connection.DataSource; // MessageBox.Show(s); //} //else //{ // MessageBox.Show("ارتباط با پایگاه داده ناموفق بود"); //} return; } } catch (Exception ex) { MessageBox.Show(ex.Message, "پیغام خطای پایگاه داده"); } }
public void AddOrder(DateTime date, DateTime endDate, ArrayList arrayDisk, int idClient, int idOrder, int cost) { using (Contex My = new Contex()) { My.Database.Log = s => System.Diagnostics.Debug.WriteLine(s); Client client = My.Clients.Where(k => k.Id == idClient).FirstOrDefault(); Order order = new Order { Client = client, ClientId = idClient, Date = date, EndDate = endDate, Status = OrderStatus.Open, Cost = cost, //Disks = arrayDisk1 }; My.Orders.Add(order); My.SaveChanges(); //using (Contex db = new Contex()) //{ for (int i = 0; i < arrayDisk.Count; i++) { int diskId = Convert.ToInt32(arrayDisk[i]); Disk disk = My.Disks.Where(k => k.Id == diskId).FirstOrDefault(); int orderId = order.Id; DiskOrder diskOrder = new DiskOrder //add DiskOrder { Disk = disk, DiskId = diskId, //Order = order, //Order = My.Orders.Where(k => k.Id == orderId).FirstOrDefault(), OrderId = orderId, }; My.DiskOrders.Add(diskOrder); } My.SaveChanges(); //My.SaveChanges(); } }
public static Employee CheckedEmployee(Employee emp, string firstname, string lastname, string secondname, string phonenumber, string login, string password, int roleId, int passSer, int passNum) { Contex My = new Contex(); try { Passport pass = My.Passports.Where(k => k.Id == emp.PassportId).FirstOrDefault(); if (emp.FirstName.Equals(firstname)) { if (emp.LastName.Equals(lastname)) { if (emp.SecondName.Equals(secondname)) { if (emp.PhoneNumber.Equals(phonenumber)) { if (emp.Login.Equals(login)) { if (emp.Password.Equals(password)) { if (emp.RoleId.Equals(roleId)) { if (pass.number.Equals(passNum)) { if (pass.series.Equals(passSer)) { return(emp); } } } } } } } } } return(null); } catch { return(null); } }
public static bool Guardar(NotasCredito Notas) { bool paso = false; try { Contex Contex = new Contex(); var estudiante = BLL.EstudiantesBLL.Buscar(Notas.EstudianteID); estudiante.Monto += Notas.Monto; BLL.EstudiantesBLL.Modificar(estudiante); Contex.Notas.Add(Notas); Contex.SaveChanges(); paso = true; } catch (Exception) { throw; } return(paso); }
public void Login(LoginBM user, string sessionId) { if (!this.Contex.Sessions.Any(login => login.SessionId == sessionId)) { this.Contex.Sessions.Add(new Session() { SessionId = sessionId }); this.Contex.SaveChanges(); } var session = Contex.Sessions.FirstOrDefault(x => x.SessionId == sessionId); var userToLog = Contex.Users.FirstOrDefault(x => x.Username == user.Username && x.Password == user.Password); if (userToLog != null) { session.User = userToLog; session.IsActive = true; Contex.SaveChanges(); } }
public static bool Eliminar(int EstudianteId) { bool paso = false; try { Contex contex = new Contex(); var nota = contex.Notas.Find(EstudianteId); var estudiante = BLL.EstudiantesBLL.Buscar(nota.EstudianteID); estudiante.Monto -= nota.Monto; BLL.EstudiantesBLL.Modificar(estudiante); contex.Notas.Remove(nota); contex.SaveChanges(); paso = true; } catch (Exception) { throw; } return(paso); }