protected override void OnSaveToolBarItem() { ReadData(_activeProvince); using (var dbContext = new FarnahadManufacturingDbContext()) { if (_activeProvince.Id > 0) { dbContext.Entry(_activeProvince).State = EntityState.Modified; dbContext.SaveChanges(); IsEditing(); } else { _activeProvince.CreatedByUserId = ApplicationSessionService.GetActiveUserId(); _activeProvince.CreatedDateTime = ApplicationSessionService.GetNowDateTime(); dbContext.Provinces.Add(_activeProvince); dbContext.SaveChanges(); OnAddToolBarItem(); } } MessageBoxService.SaveConfirmation(_activeProvince.Title); LoadSearchGridControl(); }
private void LoadSearchGridControlData(string partNumber, string description, object partType) { using (var dbContext = new FarnahadManufacturingDbContext()) { var partsQueryable = dbContext.Parts.OrderBy(item => item.Id) .Include(item => item.PartCosts) .Include(item => item.PartReorderInformations) .Include(item => item.LastChangedByUser) .AsQueryable(); if (!string.IsNullOrEmpty(partNumber)) { partsQueryable = partsQueryable.Where(item => item.Number.Contains(partNumber)); } if (!string.IsNullOrEmpty(description)) { partsQueryable = partsQueryable.Where(item => item.Description.Contains(description)); } if (partType is PartType partTypeValue) { partsQueryable = partsQueryable.Where(item => item.PartType == partTypeValue); } _parts = partsQueryable.Paginate(PaginationUserControl.CurrentPage); SearchGridControl.ItemsSource = _parts; PaginationUserControl.UpdateRecordsDetail(_parts.Count, partsQueryable.Count()); } }
private Category GetCategory(int categoryId) { using (var dbContext = new FarnahadManufacturingDbContext()) { return(dbContext.Categories.First(item => item.Id == categoryId)); } }
private string GetPartDescription(int partId) { using (var dbContext = new FarnahadManufacturingDbContext()) { return(dbContext.Parts.FirstOrDefault(item => item.Id == partId)?.Description); } }
private void DeleteButtonOnToolBarItemClick(object sender, ItemClickEventArgs e) { if (CategoryTreeListControl.SelectedItem is Category category) { if (MessageBoxService.AskForDelete(category.Title) == true) { using (var dbContext = new FarnahadManufacturingDbContext()) { var categoryInDb = dbContext.Categories.First(item => item.Id == category.Id); if (dbContext.Categories.Any(item => item.ParentCategoryId == categoryInDb.Id)) { MessageBoxService.CannotDeleteParent(categoryInDb.Title); } else { dbContext.Categories.Remove(categoryInDb); dbContext.SaveChanges(); LoadCategories(); LoadCategoriesTreeList(); } } } } else { // No Valid Item Selected } }
private void LoadSearchGridControlData(string productTitle, string productDescription, string partNumber, string customerNumber) { using (var dbContext = new FarnahadManufacturingDbContext()) { var productsQueryable = dbContext.Products .Include(item => item.ProductPrices) .Include(item => item.ProductSubstitutes) .Include(item => item.ProductAssociatePrices) .OrderBy(item => item.Id).AsQueryable(); if (!string.IsNullOrEmpty(productTitle)) { productsQueryable = productsQueryable.Where(item => item.Title.Contains(productTitle)); } if (!string.IsNullOrEmpty(productDescription)) { productsQueryable = productsQueryable.Where(item => item.Description.Contains(productDescription)); } if (!string.IsNullOrEmpty(partNumber)) { productsQueryable = productsQueryable.Where(item => item.Part.Number.Contains(partNumber)); } // TODO: Customer Number //if (!string.IsNullOrEmpty(customerNumber)) // productsQueryable = productsQueryable.Where(item => item.Customer.Number.Contains(customerNumber)); var totalRecordsCount = productsQueryable.Count(); _products = productsQueryable.Paginate(PaginationUserControl.CurrentPage); SearchGridControl.ItemsSource = _products; PaginationUserControl.UpdateRecordsDetail(_products.Count, totalRecordsCount); } }
protected override void OnSaveToolBarItem() { ReadData(_activeUser); if (!string.IsNullOrEmpty(_activeUser.Password)) { if (_activeUser.Id > 0) { using (var dbContext = new FarnahadManufacturingDbContext()) { var userInDb = dbContext.Users .Include(item => item.LocationGroupMembers) .First(item => item.Id == _activeUser.Id); userInDb.FirstName = _activeUser.FirstName; userInDb.LastName = _activeUser.LastName; userInDb.UserName = _activeUser.UserName; userInDb.Email = _activeUser.Email; userInDb.PhoneNumber = _activeUser.PhoneNumber; userInDb.Initial = _activeUser.Initial; userInDb.IsActive = _activeUser.IsActive; userInDb.PasswordSalt = _activeUser.PasswordSalt; userInDb.Password = _activeUser.Password; userInDb.LocationGroupMembers.Clear(); foreach (var locationGroup in _activeUser.LocationGroupMembers) { var locationGroupInDb = dbContext.LocationGroups.Find(locationGroup.Id); userInDb.LocationGroupMembers.Add(locationGroupInDb); } dbContext.SaveChanges(); IsEditing(); } } else { _activeUser.CreatedDateTime = ApplicationSessionService.GetNowDateTime(); using (var dbContext = new FarnahadManufacturingDbContext()) { dbContext.Users.Add(_activeUser); foreach (var locationGroup in _activeUser.LocationGroupMembers) { locationGroup.CreatedByUserId = ApplicationSessionService.GetActiveUserId(); locationGroup.CreatedDateTime = ApplicationSessionService.GetNowDateTime(); } dbContext.SaveChanges(); OnAddToolBarItem(); } } } else { MessageBox.Show("رمز عبور باید تنظیم شود"); } MessageBoxService.SaveConfirmation(_activeUser.UserName); LoadSearchGridControl(); }
private ProductCategory GetProductCategory(int productCategoryId) { using (var dbContext = new FarnahadManufacturingDbContext()) { return(dbContext.ProductCategories.First(item => item.Id == productCategoryId)); } }
private void LoadProducts(string productName = null, string productDescription = null, string customerNumber = null, string partNumber = null) { using (var dbContext = new FarnahadManufacturingDbContext()) { var productsQueryable = dbContext.Products.OrderBy(item => item.Id).AsQueryable(); if (!string.IsNullOrEmpty(productName)) { productsQueryable = productsQueryable.Where(item => item.Title.Contains(productName)); } if (!string.IsNullOrEmpty(productDescription)) { productsQueryable = productsQueryable.Where(item => item.Description.Contains(productDescription)); } // TODO: add customer... //if (!string.IsNullOrEmpty(customerNumber)) // productsQueryable = productsQueryable.Where(item => item.c); if (!string.IsNullOrEmpty(partNumber)) { productsQueryable = productsQueryable.Where(item => item.Part.Number.Contains(partNumber)); } var products = productsQueryable.Paginate(PaginationUserControl.CurrentPage); SearchGridControl.ItemsSource = products; PaginationUserControl.UpdateRecordsDetail(products.Count, productsQueryable.Count()); } }
private void LoadSearchGridControlData(string searchName = null, int?provinceId = null, int?cityId = null) { using (var dbContext = new FarnahadManufacturingDbContext()) { var vendorsQueryable = dbContext.Vendors.OrderBy(item => item.Id) .Include(item => item.Addresses) .Include("Addresses.ContactInformations") .Include(item => item.CreatedByUser).AsQueryable(); if (!string.IsNullOrEmpty(searchName)) { vendorsQueryable = vendorsQueryable.Where(item => item.Title.Contains(searchName)); } if (provinceId != null) { vendorsQueryable = vendorsQueryable.Where(item => item.Addresses.Any(a => a.ProvinceId == provinceId)); } if (cityId != null) { vendorsQueryable = vendorsQueryable.Where(item => item.Addresses.Any(a => a.CityId == cityId)); } var totalRecordsCount = vendorsQueryable.Count(); _vendors = vendorsQueryable.Paginate(PaginationUserControl.CurrentPage); SearchGridControl.ItemsSource = _vendors; PaginationUserControl.UpdateRecordsDetail(_vendors.Count, totalRecordsCount); } }
protected override void OnSaveToolBarItem() { ReadData(_activeCarrier); if (_activeCarrier.Id > 0) { using (var dbContext = new FarnahadManufacturingDbContext()) { var carrier = dbContext.Carriers.Find(_activeCarrier.Id); var carrierServices = dbContext.CarrierServices .Where(item => item.CarrierId == carrier.Id); foreach (var carrierService in carrierServices) { var tempCarrier = _carrierServices.FirstOrDefault(item => item.Id == carrierService.Id); if (tempCarrier == null) { dbContext.CarrierServices.Remove(carrierService); } else { carrierService.Title = tempCarrier.Title; carrierService.Code = tempCarrier.Code; dbContext.Entry(carrierService).State = EntityState.Modified; } } foreach (var carrierService in _carrierServices.Where(item => item.Id <= 0)) { carrierService.Carrier = carrier; dbContext.CarrierServices.Add(carrierService); } carrier.Title = _activeCarrier.Title; carrier.Scac = _activeCarrier.Scac; carrier.Description = _activeCarrier.Description; carrier.IsActive = _activeCarrier.IsActive; dbContext.SaveChanges(); IsEditing(); } } else { _activeCarrier.CreatedByUserId = ApplicationSessionService.GetActiveUserId(); _activeCarrier.CreatedDateTime = ApplicationSessionService.GetNowDateTime(); using (var dbContext = new FarnahadManufacturingDbContext()) { _activeCarrier.CarrierServices.AddRange(_carrierServices); dbContext.Carriers.Add(_activeCarrier); dbContext.SaveChanges(); } OnAddToolBarItem(); } MessageBoxService.SaveConfirmation(_activeCarrier.Title); LoadSearchGridControl(); }
private void LoadDistanceUoms() { using (var dbContext = new FarnahadManufacturingDbContext()) { var uoms = dbContext.Uoms.AsNoTracking().Where(item => item.UomType == UomType.Length).ToList(); DistanceUomComboBoxEdit.ItemsSource = uoms; } }
private void LoadCategories() { using (var dbContext = new FarnahadManufacturingDbContext()) { var categories = dbContext.Categories.AsNoTracking().ToList(); _categories = new ObservableCollection <Category>(categories); } }
private void GenerateNumberButtonOnClick(object sender, RoutedEventArgs e) { using (var dbContext = new FarnahadManufacturingDbContext()) { var maxNumber = dbContext.Locations.Max(item => (int?)item.Number) ?? 0; LocationNumberSpinEdit.EditValue = maxNumber + 1; } }
private void LoadCountryComboBox() { using (var dbContext = new FarnahadManufacturingDbContext()) { var countries = dbContext.Countries.Select(item => new { Title = item.Title, Id = item.Id }).ToList(); CountryComboBox.ItemsSource = countries; } }
private void LoadProductCategories() { using (var dbContext = new FarnahadManufacturingDbContext()) { var productCategories = dbContext.ProductCategories.Include(item => item.Products).ToList(); _productCategories = new ObservableCollection <ProductCategory>(productCategories); } }
private void LoadCountryComboBox() { using (var dbContext = new FarnahadManufacturingDbContext()) { var countries = dbContext.Countries.AsNoTracking().ToList(); CurrentCountryComboBox.ItemsSource = countries; } }
public static DateTime GetNowDateTime() { using (var dbContext = new FarnahadManufacturingDbContext()) { var query = dbContext.Database.SqlQuery <DateTime>("SELECT getdate()"); return(query.AsEnumerable().First()); } }
public static int GetActiveUserId() { using (var dbContext = new FarnahadManufacturingDbContext()) { var user = dbContext.Users.FirstOrDefault(); return(user.Id); } }
public static string GetActiveUserName() { using (var dbContext = new FarnahadManufacturingDbContext()) { var userId = GetActiveUserId(); return(dbContext.Users.Find(userId).UserName); } }
private void LoadUomComboBox() { using (var dbContext = new FarnahadManufacturingDbContext()) { var uoms = dbContext.Uoms.AsNoTracking().ToList(); UomComboBoxEdit.ItemsSource = uoms; } }
private void LoadCarrierServices(int carrierId) { using (var dbContext = new FarnahadManufacturingDbContext()) { _carrierServices = new ObservableCollection <CarrierService>( dbContext.CarrierServices.Where(item => item.CarrierId == carrierId).ToList()); } }
private ObservableCollection <ProductAssociatePrice> GetProductAssociates(int productId) { using (var dbContext = new FarnahadManufacturingDbContext()) { var productAssociatePrices = dbContext.ProductAssociatePrices.AsNoTracking() .Where(item => item.ProductId == productId).ToList(); return(new ObservableCollection <ProductAssociatePrice>(productAssociatePrices)); } }
private void LoadWeightUomComboBox() { using (var dbContext = new FarnahadManufacturingDbContext()) { var weightUoms = dbContext.Uoms.AsNoTracking() .Where(item => item.UomType == UomType.Weight).ToList(); WeightUomComboBoxEdit.ItemsSource = weightUoms; } }
public LoginWindow() { InitializeComponent(); using (var dbContext = new FarnahadManufacturingDbContext()) { dbContext.Database.Initialize(true); } this.Loaded += OnLoaded; }
private void LoadProvinceComboBox(int countryId) { using (var dbContext = new FarnahadManufacturingDbContext()) { var provinces = dbContext.Provinces.Where(item => item.CountryId == countryId) .Select(item => new { Title = item.Title, Id = item.Id }).ToList(); ProvinceComboBox.ItemsSource = provinces; } }
private void LoadCarrierComboBoxEdit() { using (var dbContext = new FarnahadManufacturingDbContext()) { var carriers = dbContext.Carriers.AsNoTracking() .Select(item => new { Title = item.Title, Id = item.Id }) .ToList(); DefaultCarrierComboBoxEdit.ItemsSource = carriers; } }
private void LoadShippingTermComboBoxEdit() { using (var dbContext = new FarnahadManufacturingDbContext()) { var shippingTerms = dbContext.ShippingTerms.AsNoTracking() .Select(item => new { Title = item.Title, Id = item.Id }) .ToList(); DefaultShippingTermComboBoxEdit.ItemsSource = shippingTerms; } }
private void LoadAddressTypeComboBox() { using (var dbContext = new FarnahadManufacturingDbContext()) { var addressTypes = dbContext.AddressTypes.AsNoTracking() .Select(item => new { Title = item.Title, Id = item.Id }) .ToList(); CurrentAddressTypeComboBox.ItemsSource = addressTypes; AddressesAddressTypeComboBox.ItemsSource = addressTypes; } }
private void LoadCountryComboBox() { using (var dbContext = new FarnahadManufacturingDbContext()) { var countries = dbContext.Countries.Select(item => new FmComboModel <int> { Value = item.Id, Title = item.Title, }).ToList(); CountryComboBoxEdit.ItemsSource = countries; } }