public LoginResponse GetUserForLogin(string email, string password) { LoginResponse loginResponse = new LoginResponse(); using (MyDb db = new MyDb()) { try { loginResponse.User = db.Users.FirstOrDefault(x => x.Email == email && x.Password == password && x.isActive == true); if (loginResponse.User == null) { loginResponse.SetError(Common.SystemConstant.SystemConstants.ERRORS.NOTFOUND); } else { Token token = new Token(); token.Value = RandomSfr.Generate(50); token.ExpireDate = DateTime.Now.AddDays(1); loginResponse.Token = token; loginResponse.SetError(Common.SystemConstant.SystemConstants.ERRORS.SUCCESSFUL); } } catch (Exception) { loginResponse.SetError(Common.SystemConstant.SystemConstants.ERRORS.SYSTEMERROR); } } return(loginResponse); }
public ActivateResponse ActivateUser(User user) { ActivateResponse response = new ActivateResponse(); using (MyDb db = new MyDb()) { try { User user2 = db.Users.FirstOrDefault(t => t.Email == user.Email); if (user.ValidationKey == Security.sha512encrypt(user2.ValidationKey)) { user2.isActive = true; db.Entry(user2).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); response.SetError(SystemConstants.ERRORS.SUCCESSFUL); } else { response.SetError(SystemConstants.ERRORS.NOTFOUND); } } catch (Exception ex) { response.SetError(SystemConstants.ERRORS.SYSTEMERROR); } return(response); } }
private static List <HausanschlussImport> LoadMergedHausanschlussImports([NotNull] MyDb dbRaw) { var isnLocations = dbRaw.Fetch <HausanschlussImport>(); var isnLocationsSup = dbRaw.Fetch <HausanschlussImportSupplement>(); var mergedLocs = new List <HausanschlussImport>(); foreach (var sup in isnLocationsSup) { var mainlocs = isnLocations.Where(x => Math.Abs(x.Lat - sup.HaLat) < 0.00000000000001 && Math.Abs(x.Lon - sup.HaLon) < 0.00000000000001 && x.ObjectID == sup.HaObjectid) .ToList(); if (mainlocs.Count > 1) { throw new FlaException("found multiple candidates for " + sup.HaObjectid); } if (mainlocs.Count == 0) { throw new FlaException("No object found to match for " + sup.HaObjectid); } HausanschlussImport hai1 = new HausanschlussImport(mainlocs[0], sup.TargetStandort); hai1.Adress = sup.TargetComplexName; hai1.Isn = sup.TargetIsn; mergedLocs.Add(hai1); } foreach (var location in isnLocations) { mergedLocs.Add(location); } return(mergedLocs); }
public ProductListResponse GetProductList() { ProductListResponse response = new ProductListResponse(); using (MyDb db = new MyDb()) { try { response.Products = db.Products.ToList(); if (response.Products == null) { response.SetError(Common.SystemConstant.SystemConstants.ERRORS.NOTFOUND); } else { response.SetError(Common.SystemConstant.SystemConstants.ERRORS.SUCCESSFUL); } } catch (Exception ex) { response.SetError(Common.SystemConstant.SystemConstants.ERRORS.SYSTEMERROR); } return(response); } }
public MainWindow() { InitializeComponent(); mdb = new MyDb(); Plane a = new Plane { id = 1, model = "Airbus" }; mdb.Plane.Add(a); mdb.SaveChanges(); //Worker worker = new Worker { id = 1, name = "Tom", planeId = 1 }; //a.Workers.Add(worker); //pc.Plane.Add(a); //wc.Worker.Add(worker); //pc.SaveChanges(); //wc.SaveChanges(); workerGrid.ItemsSource = mdb.Worker.Local.ToBindingList(); this.Closing += MainWindow_Closing; }
public void UpdateAccount(Account account) { if (!MyDb.UpdateData(account.Save(), account.Name, "Account")) { throw new ArgumentException("Account is already exists"); } }
public override void Delete() { if (Selected != null) { if (MessageBox.Show("Souhaitez-vous rééllement supprimer cet élément ?", "Suppresion", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) { try { Casting itemToDelete = Selected.ToEntity(); MyDb.Casting.Remove(itemToDelete); MyDb.SaveChanges(); ReloadDatas(); return; } catch (Exception ex) { MessageBox.Show("Erreur lors de la sauvegarde des données : " + ex.Message); } //Erreur à la suppression MyDb = new MegaProductionBDDEntities(); } } }
public void RemoveAccount(Account account) { if (!MyDb.RemoveData(account.Name, "Account")) { throw new ArgumentException("Account is not exists", "account"); } }
public override void Update() { if (Selected != null) { //Ouverture de la fenêtre d'ajout CastingItemViewModel itemToUpdate = Selected; CastingItemWindow window = new CastingItemWindow(itemToUpdate); window.ShowDialog(); if (window.DialogResult.HasValue && window.DialogResult == true) { //On a appuyé sur OK //Sauvegarde try { Casting toAdd = itemToUpdate.ToEntity(); MyDb.SaveChanges(); ReloadDatas(); return; } catch (Exception ex) { MessageBox.Show("Erreur lors de la sauvegarde des données : " + ex.Message); } } //On a appuyé sur annuler ou on a crash dans la sauvegrde de l'item MyDb = new MegaProductionBDDEntities(); } }
public override void Add() { PartenaireDiffusionItemViewModel item = new PartenaireDiffusionItemViewModel(null); PartenaireDiffusionItemWindow window = new PartenaireDiffusionItemWindow(item); window.ShowDialog(); if (window.DialogResult.HasValue && window.DialogResult == true) { try { PartenaireDiffusion toAdd = item.ToEntity(); MyDb.PartenaireDiffusion.Add(toAdd); MyDb.SaveChanges(); ReloadDatas(); return; } catch (Exception e) { MessageBox.Show("Erreur lors de la sauvegarde des données : " + e.Message); } } MyDb = new MegaProductionBDDEntities(); }
public void FormattingWithSqlParameterThatIsNotNull() { var cmd = new SqlCommand(); cmd.Parameters.Add(new SqlParameter("Test", SqlDbType.NVarChar)); var db = new MyDb(); Assert.AreEqual("\n\t -> @0 [SqlParameter, String] = \"\"", db.FormatCommand(cmd)); }
private SaveableEntry([NotNull] MyDb sqliteDB, [NotNull] string tableName, [NotNull] ILogger logger) : base(logger, sqliteDB.MyStage, "SaveableEntry") { SqliteDB = sqliteDB; TableName = tableName; }
public override void Update() { if (Selected != null) { OffreItemViewModel item = Selected; OffreItemWindow window = new OffreItemWindow(item); window.ShowDialog(); if (window.DialogResult.HasValue && window.DialogResult == true) { try { Offre toUpdate = Selected.ToEntity(); MyDb.SaveChanges(); ReloadDatas(); return; } catch (Exception e) { MessageBox.Show("Erreur lors de la sauvegarde : " + e.Message); } } MyDb = new MegaProductionBDDEntities(); } }
private void SaveToolStripButton_Click(object sender, EventArgs e) { //overwriting the table //MyDb.RunSql("SET IDENTITY_INSERT Приём ON"); MyDb.RunSql("TRUNCATE TABLE Приём"); for (int r = 0; r < DoctorVisitsDataGridView.Rows.Count; r++) { var row = DoctorVisitsDataGridView.Rows[r]; if (row.Cells[0].Value == null) { break; } var id = row.Cells[0].Value.ToString(); var patientId = row.Cells[1].Value.ToString(); var doctorId = row.Cells[2].Value.ToString(); var officeId = row.Cells[3].Value.ToString(); var visitTime = row.Cells[4].Value.ToString(); MyDb.RunSql("SET IDENTITY_INSERT Приём ON \n" + "INSERT INTO Приём (Ид, ПациентИд, ВрачИд, КабинетИд, ВремяПриёма) " + $"VALUES ('{id}', '{patientId}', '{doctorId}', '{officeId}', '{visitTime}') "); } MyDb.RunSql(@"SET IDENTITY_INSERT Приём OFF"); }
public ConnectionFactory(string conStr) { _cnx = GetSqlConnection(conStr); //_cnx.Open(); //_tsn = _cnx.BeginTransaction(); _mydb = MyDb.Init((DbConnection)_cnx, 2000); }
public override void Update() { if (Selected != null) { ContenuEditorialItemViewModel itemToUpate = Selected; ContenuEditorialItemWindow window = new ContenuEditorialItemWindow(itemToUpate); window.ShowDialog(); if (window.DialogResult.HasValue && window.DialogResult == true) { try { ContenuEditorial toUpdate = itemToUpate.ToEntity(); MyDb.SaveChanges(); ReloadDatas(); return; } catch (Exception e) { MessageBox.Show("Erreur lors de la sauvegarde des données : " + e.Message); } } MyDb = new MegaProductionBDDEntities(); } }
public async Task <IActionResult> Edit(int id, [Bind("ID,Name,Username,Email,Password,LiveStream")] MyDb myDb) { if (id != myDb.ID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(myDb); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MyDbExists(myDb.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction("Index")); } return(View(myDb)); }
public GetBasketResponse GetProductsOfUser(int id) { GetBasketResponse response = new GetBasketResponse(); using (MyDb db = new MyDb()) { try { List <Basket> basket = db.Baskets.Where(x => x.User_ID == id).ToList(); foreach (var item in basket) { item.Product = db.Products.FirstOrDefault(x => x.ID == item.Product_ID); } response.Baskets = basket; response.Count = basket.Count; if (response.Baskets == null) { response.SetError(Common.SystemConstant.SystemConstants.ERRORS.NOTFOUND); } else { response.SetError(Common.SystemConstant.SystemConstants.ERRORS.SUCCESSFUL); } } catch (Exception ex) { response.SetError(Common.SystemConstant.SystemConstants.ERRORS.SYSTEMERROR); } return(response); } }
public override void Delete() { if (Selected != null) { if (MessageBox.Show("Voulez-vous réellement supprimer cet élément ? ", "Suppression", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) { try { Offre toRemove = Selected.ToEntity(); MyDb.Offre.Remove(toRemove); MyDb.SaveChanges(); ReloadDatas(); return; } catch (Exception e) { MessageBox.Show("Erreur lors de la sauvegarde des données : " + e.Message); } } MyDb = new MegaProductionBDDEntities(); } }
public TakmicenjeValidator(MyDb _db) { db = _db; _listaTakmicenja = db.Takmicenja.Select(x => x.Naziv).ToList(); _listaIgraca = db.Igraci.ToList(); }
public void RemoveShopLot(ShopLot lot) { if (!MyDb.RemoveData(lot.Name, "ShopLot")) { throw new ArgumentException("Goods is not exists"); } }
public void UpdateShopLot(ShopLot shopLot) { if (!MyDb.UpdateData(shopLot.Save(), shopLot.Name, "ShopLot")) { throw new ArgumentException("Goods is already exists"); } }
public static void UpdateClient(this ClientViewModel viewModel, MyDb context) { var client = context.Clients.Find(viewModel.Id); client.FirstName = viewModel.FirstName; client.LastName = viewModel.LastName; client.DateOfBirth = viewModel.DateOfBirth; }
public ShopLot GetShopLot(string name) { var buffer = MyDb.GetData(name, "ShopLot"); ShopLot result = new ShopLot("null", "null", "null", 1); result.Load(buffer); return(result); }
public Account GetAccount(string name) { var buffer = MyDb.GetData(name, "Account"); Account result = new Account("null", "null"); result.Load(buffer); return(result); }
private void AddPatient() { MyDb.AddPatientToDataBase( FullnameTB.Text, BirthDateTB.Text, PatientAddressTB.Text); mainForm.UpdateAllView(); }
public MyApprovalsController(IMapper mapper) { _db = new MyDb(); _mapper = mapper; _service = new ApprovalService(mapper); var user = User; }
public MainViewModel(string connectionName = "name=MyDb") { _context = new MyDb(connectionName); _context.Clients.Load(); Clients = new ClientsCollection(_context.Clients.Local.Select(client => client.ToViewModel())); DeleteCommand = new RelayCommand(o => Delete(o as ClientViewModel)); CreateCommand = new RelayCommand(o => Create()); SaveChangesCommand = new RelayCommand(o => SaveChanges()); }
void LoadData() { var result = MyDb.GetInstance().HOCBONGs.Select(a => new { a.Mahb, a.Tenhb, a.Sotien }); dtgvHB.DataSource = result.ToList(); dtgvHB.Columns[0].HeaderText = "Mã HB"; dtgvHB.Columns[1].HeaderText = "Tên HB"; dtgvHB.Columns[2].HeaderText = "Số tiền"; }
private void btn_xoa_Click(object sender, EventArgs e) { NHANVIEN nv = MyDb.GetInstance().NHANVIENs.Where(p => p.MaNV == txt_MaNV.Text.Trim()).SingleOrDefault(); User user = MyDb.GetInstance().Users.Where(p => p.MaNV == nv.MaNV).SingleOrDefault(); MyDb.GetInstance().Users.Remove(user); nhanvienBLL.Delete(nv); Shownhanvien(nhanvienBLL.GetAll()); }
public void FormattingWithNullValue() { var db = new MyDb(); Assert.AreEqual("sql @0\n\t -> @0 [] = \"\"", db.FormatCommand("sql @0", new object[] { null })); }
public void FormattingWithStringValue() { var db = new MyDb(); Assert.AreEqual("sql @0\n\t -> @0 [String] = \"value\"", db.FormatCommand("sql @0", new object [] {"value"})); }