public BDVisitPrice VisitPriceSaveChange(BDVisitPrice _bDVisitPrice) { try { // BDVisitPrice operation add & edit var dbVisitPrice = _contextDatabase.BDVisitPrices.SingleOrDefault(s => s.VisitPriceID == _bDVisitPrice.VisitPriceID); if (dbVisitPrice != null) { // Update BDVisitPrice _contextDatabase.Entry(dbVisitPrice).CurrentValues.SetValues(_bDVisitPrice); _contextDatabase.BDVisitPrices.Attach(dbVisitPrice); _contextDatabase.SaveChanges(); return dbVisitPrice; } else { // Insert BDVisitPrice into the database _contextDatabase.BDVisitPrices.Add(_bDVisitPrice); _contextDatabase.SaveChanges(); return _bDVisitPrice; } } catch (Exception ex) { throw; } return null; }
public bool ValidateVisitPrice(BDVisitPrice _bDVisitPrice) { try { var query = _contextDatabase.BDVisitPrices.AsQueryable(); if (_bDVisitPrice.VisitPriceID != null && _bDVisitPrice.VisitPriceID > 0) query = query.Where(a => a.VisitPriceID != _bDVisitPrice.VisitPriceID).AsQueryable(); query = query.Where(a => a.VisitTypeID == _bDVisitPrice.VisitTypeID).AsQueryable(); query = query.Where(a => (a.FromDate >= _bDVisitPrice.ToDate && a.ToDate <= _bDVisitPrice.ToDate) || (a.FromDate <= _bDVisitPrice.FromDate && a.ToDate >= _bDVisitPrice.FromDate)).AsQueryable(); return !query.Any(); } catch (Exception ex) { throw; } return false; }
/// <summary> /// ma object to control in UI form /// </summary> /// <param name="newObj"></param> private void ObjectToUI(BDVisitPrice newObj) { txtId.Text = newObj.VisitPriceID.ToString(); dateTimePicker1.Value = newObj.FromDate; dateTimePicker2.Value = newObj.ToDate; numericUpDown2.Value = newObj.VisitPrice; cbx_VisitTypeName.SelectedValue = newObj.VisitTypeID; }
/// <summary> /// Get data from UI to create new Object /// </summary> /// <returns></returns> private BDVisitPrice ObjectFromUI() { BDVisitPrice newObj = new BDVisitPrice(); newObj.VisitPriceID = int.Parse(txtId.Text); newObj.FromDate = dateTimePicker1.Value; newObj.ToDate = dateTimePicker2.Value; newObj.VisitPrice = numericUpDown2.Value; newObj.VisitTypeID = int.Parse(cbx_VisitTypeName.SelectedValue.ToString()); return newObj; }