public async Task <bool> Post(FuelPrelevement myPrelevement) { using (var db = new StationContext()) { if (myPrelevement.PrelevementGuid == Guid.Empty) { myPrelevement.PrelevementGuid = Guid.NewGuid(); } var citerneGuid = db.Pompes.Find(myPrelevement.PompeGuid).CiterneGuid; if (citerneGuid != null) { myPrelevement.CiterneGuid = (Guid)citerneGuid; } else { throw new ArgumentException("CAN_NOT_FIND_CITERNE"); } myPrelevement.CurrentPrice = (await FuelManager.GetFuelCurrentPrice(db.Pompes.Find(myPrelevement.PompeGuid).Citerne.FuelGuid)); myPrelevement.DateAdded = DateTime.Now; myPrelevement.LastEditDate = DateTime.Now; db.Set <FuelPrelevement>().Add(myPrelevement); return(await db.SaveChangesAsync() > 0); } }
internal async static Task <Price> GetFuelLastPrice(Guid fuelGuid) { return(await Task.Run(async() => { using (var db = new StationContext()) return (await db.Fuels.FindAsync(fuelGuid)).Prices.Where(p => p.FromDate <= DateTime.Now).OrderByDescending(p => p.FromDate).First(); })); }
public async Task <List <CompanyCard> > GetCompaniesCards() { return(await Task.Run(() => { using (var db = new StationContext()) return db.Companies.Where(c => !c.IsDeleted).ToList().Select(c => new CompanyCard(c)).ToList(); })); }
public async Task <List <FuelDeliveryCard> > GetCiterneStocks(Guid citerneGuid) { return(await Task.Run(() => { using (var db = new StationContext()) return db.Citernes.Find(citerneGuid)?.Deliveries.Where(d => !d.IsDeleted).OrderByDescending(s => s.DateAdded).ToList().Select(s => new FuelDeliveryCard(s)).ToList(); })); }
public async Task <bool> Post(Purchase myPurchase) { using (var db = new StationContext()) { switch (myPurchase.ProductType) { case ProductType.Fuel: myPurchase.Sum = myPurchase.Quantity * (await FuelManager.GetFuelCurrentPrice(myPurchase.ProductGuid)); myPurchase.Description = $"{myPurchase.Quantity.ToString("0.##\\ L")} {(await db.Fuels.FindAsync(myPurchase.ProductGuid)).Libel}"; break; case ProductType.Oil: myPurchase.Sum = myPurchase.Quantity * (await OilManager.StaticGet(myPurchase.ProductGuid)).CurrentUnitPrice; myPurchase.Description = $"{"Bidon".ToQuantity((int) myPurchase.Quantity)} {(await db.Oils.FindAsync(myPurchase.ProductGuid)).Libel}"; break; } if (myPurchase.PurchaseGuid == Guid.Empty) { myPurchase.PurchaseGuid = Guid.NewGuid(); } if (myPurchase.PurchaseState == PurchaseState.Paid) { myPurchase.PurchaseDate = DateTime.Now; } myPurchase.DateAdded = myPurchase.PurchaseDate; myPurchase.LastEditDate = DateTime.Now; db.Purchases.Add(myPurchase); return(await db.SaveChangesAsync() > 0); } }
public async Task <List <Citerne> > GetCiternes() { return(await Task.Run(() => { using (var db = new StationContext()) return db.Citernes.Where(c => !c.IsDeleted).OrderByDescending(c => c.DateAdded).ToList(); })); }
private void GetSTAFF_COUNT( ) { using (var db = new StationContext()) StaffCount = string.IsNullOrEmpty(DepartementName) ? db.Staffs.Count(s => string.IsNullOrEmpty(s.DepartementPrincipale)) : db.Staffs.Count(s => s.DepartementPrincipale == DepartementName); }
/// <summary> /// Represente un client /// </summary> /// <param name="newCustomer"></param> /// <exception cref="InvalidOperationException">CAN_NOT_CREAT_STAFF_PROFILE</exception> /// <returns></returns> //[PrincipalPermission(SecurityAction.Demand, Role = SecurityClearances.CustomerWrite)] public bool AddCustomer(Customer newCustomer) { Guard.WhenArgument(newCustomer.Person.FullName, "CUSTOMER_NAME_CAN_NOT_BE_EMPTY").IsNullOrEmpty().IsEqual("Inconnue").Throw(); using (var db = new StationContext()) { if (newCustomer.CustomerGuid == Guid.Empty) { newCustomer.CustomerGuid = Guid.NewGuid(); } if (newCustomer.Person.PersonGuid == Guid.Empty) { newCustomer.Person.PersonGuid = Guid.NewGuid(); } // ReSharper disable once PossibleNullReferenceException var userTrace = (Guid)Membership.GetUser().ProviderUserKey; newCustomer.DateAdded = DateTime.Now; newCustomer.AddUserGuid = userTrace; newCustomer.LastEditDate = DateTime.Now; newCustomer.LastEditUserGuid = userTrace; db.Set <Person>().Add(newCustomer.Person); db.Customers.Add(newCustomer); return(db.SaveChanges() > 0); } }
internal static bool StaticNewTransaction(Transaction newTransaction) { if (TransactionExist(newTransaction)) { throw new InvalidOperationException("TRANSACTION_REFERENCE_ALREADY_EXIST"); } if (newTransaction.TransactionDate < DateTime.Today.AddDays(-1)) { throw new InvalidOperationException("TRANSACTION_DATE_NOT_VALIDE"); } using (var db = new StationContext()) { newTransaction.TransactionGuid = newTransaction.TransactionGuid == Guid.Empty ? Guid.NewGuid() : newTransaction.TransactionGuid; var transDate = newTransaction.TransactionDate.GetValueOrDefault(); newTransaction.TransactionDate = new DateTime(transDate.Year, transDate.Month, transDate.Day, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second); if (string.IsNullOrEmpty(newTransaction.Description)) { newTransaction.Description = newTransaction.Designation; } newTransaction.DateAdded = DateTime.Now; newTransaction.AddUserGuid = Guid.Empty; newTransaction.LastEditDate = DateTime.Now; newTransaction.LastEditUserGuid = Guid.Empty; db.Transactions.Add(newTransaction); return(db.SaveChanges() > 0); } }
internal async static Task <double> StaticGetSoldeCaisse(DateTime?startDate, DateTime?endDate) { return(await Task.Run(() => { using (var db = new StationContext()) { if (!db.Transactions.Any(t => !t.IsDeleted)) { return 0; } if (startDate == null || endDate == null) { return db.Transactions.Where(t => !t.IsDeleted).Sum(t => t.Amount); } return db.Transactions.Any(t => !t.IsDeleted && t.TransactionDate >= startDate && t.TransactionDate <= endDate) ? db.Transactions.Where(t => !t.IsDeleted && t.TransactionDate >= startDate && t.TransactionDate <= endDate ).Sum(t => t.Amount) : 0; } })); }
/// <summary> /// Verifie si cette reference exist /// </summary> /// <param name="theReference"></param> /// <returns></returns> public bool RefTransactionExist(string theReference) { using (var mc = new StationContext()) return (mc.Transactions.Any( s => s.TransactionReference.Equals(theReference, StringComparison.CurrentCultureIgnoreCase))); }
internal async static Task <double> StaticGetPaidSalary(DateTime?startDate, DateTime?endDate) { return(await Task.Run(() => { using (var db = new StationContext()) { if (!db.Payrolls.Any(t => !t.IsDeleted && t.IsPaid)) { return 0; } if (startDate == null || endDate == null) { return db.Payrolls.Where(t => !t.IsDeleted && t.IsPaid).Sum(t => t.FinalPaycheck); } return db.Payrolls.Any(t => !t.IsDeleted && t.IsPaid && t.DatePaid >= startDate && t.DatePaid <= endDate) ? db.Payrolls.Where(t => !t.IsDeleted && t.IsPaid && t.DatePaid >= startDate && t.DatePaid <= endDate ).Sum(t => t.FinalPaycheck) : 0; } })); }
public async Task <bool> Post(Fuel myFuel) { using (var db = new StationContext()) { if (myFuel.FuelGuid == Guid.Empty) { myFuel.FuelGuid = Guid.NewGuid(); } myFuel.DateAdded = DateTime.Now; myFuel.LastEditDate = DateTime.Now; db.Fuels.Add(myFuel); if (!myFuel.Prices.Any()) { return(db.SaveChanges() > 0); } if (myFuel.Prices.First().PriceGuid == Guid.Empty) { myFuel.Prices.First().PriceGuid = Guid.NewGuid(); } myFuel.Prices.First().ProductGuid = myFuel.FuelGuid; myFuel.Prices.First().FromDate = DateTime.Now; db.Set <Price>().Add(myFuel.Prices.First()); return(await db.SaveChangesAsync() > 0); } }
protected override void Seed(StationContext stationContext) { // This method will be called after migrating to the latest version. // You can use the DbSet<T>.AddOrUpdate() helper extension method // to avoid creating duplicate seed data. }
/// <summary> /// AllStaffsNames /// </summary> /// <returns></returns> public IEnumerable AllStaffsNames() { using (var db = new StationContext()) { return(db.Staffs.Select(s => s.Person.FirstName + " " + s.Person.LastName).Distinct().ToList()); } }
/// <summary> /// Return les nationalites des etudiants ainsi que des staffs /// </summary> /// <returns></returns> public IEnumerable AllNationalities() { var nationalities = new List <string>(); using (var db = new StationContext()) nationalities.AddRange(db.Set <Person>().Select(p => p.Nationality).ToList()); if (nationalities.Count != 0) { return(nationalities.Distinct()); } nationalities.Add("Maroc"); nationalities.Add("Mali"); nationalities.Add("US"); nationalities.Add("France"); nationalities.Add("Senegal"); nationalities.Add("Algerie"); nationalities.Add("Liberia"); nationalities.Add("Guinee"); nationalities.Add("Afrique Du Sud"); nationalities.Add("Nigeria"); nationalities.Add("Soudan"); nationalities.Add("Gambie"); nationalities.Add("Congo"); nationalities.Add("Burkina Fasso"); return(nationalities.Distinct()); }
/// <summary> /// /// </summary> /// <returns></returns> public IEnumerable AllBirthPlaces() { var birthPlace = new List <string>(); using (var db = new StationContext()) { var studentBp = (from s in db.Customers.ToList() where s.Person.BirthPlace != null select s.Person.BirthPlace).ToList().Distinct().ToList(); birthPlace.AddRange(studentBp); var staffBp = (from s in db.Staffs.ToList() where s.Person.BirthPlace != null select s.Person.BirthPlace).ToList().Distinct().ToList(); birthPlace.AddRange(staffBp); } if (birthPlace.Count != 0) { return(birthPlace.Distinct()); } birthPlace.Add("Rabat"); birthPlace.Add("Casablanca"); birthPlace.Add("Bamako"); birthPlace.Add("Toumbouctou"); birthPlace.Add("Tayba"); birthPlace.Add("Dakar"); return(birthPlace); }
/// <summary> /// /// </summary> /// <param name="staffId"></param> /// <returns></returns> public bool StaffIdExist(string staffId) { using (var db = new StationContext()) { return(db.Staffs.Any(s => s.Matricule == staffId)); } }
/// <summary> /// /// </summary> /// <param name="staffEMail"></param> /// <returns></returns> ///[PrincipalPermission(SecurityAction.Demand, Role = "Admin")] public bool StaffEmailExist(string staffEMail) { using (var db = new StationContext()) { return(db.Staffs.Any(s => s.Person.EmailAdress.Equals(staffEMail))); } }
public async Task <List <Fuel> > GetFuels(List <Guid> fuelsGuids) { return(await Task.Run(() => { using (var db = new StationContext()) return db.Fuels.Where(o => fuelsGuids.Contains(o.FuelGuid)).ToList(); })); }
private void GetSTAFF_COUNT ( ) { using (var db = new StationContext()) StaffCount = string.IsNullOrEmpty(DepartementName) ? db.Staffs.Count(s => string.IsNullOrEmpty(s.DepartementPrincipale)) : db.Staffs.Count(s => s.DepartementPrincipale == DepartementName); }
internal async static Task <double> StaticGetFuelBalance(Guid fuelGuid) { return(await Task.Run(async() => { using (var db = new StationContext()) { double diff; try { var stocks = (await db.Fuels.FindAsync(fuelGuid))?.Citernes.Where(c => !c.IsDeleted).Select(c => c.Deliveries.Where(d => !d.IsDeleted)).Sum(s => s.Sum(l => l.QuantityDelivered)); if (stocks == null) { return 0; } var prelevs = (await db.Fuels.FindAsync(fuelGuid))?.Citernes.Where(c => !c.IsDeleted).Select(p => p.Prelevements.Where(l => !l.IsDeleted)).Sum(p => p.Sum(v => v.Result)); if (prelevs == null) { return 0; } diff = (double)(stocks - prelevs); } catch (Exception exception) { DebugHelper.WriteException(exception); return 0; } return diff < 0 ? 0 : diff; } })); }
///// <summary> ///// Card Renvoyer Apres une Recherche ///// </summary> //public SearchCard(Guid personGuid, Guid anneeScolaireGuid) //{ // using (var db = new SchoolContext()) // { // PersonGuid = personGuid; // FullName = db.Student.Find(personGuid)?.FullName; // PhotoIdentity = db.Student.Find(personGuid)?.PhotoIdentity; // var ins = db.Inscription.FirstOrDefault(i => i.AnneeScolaireGuid == anneeScolaireGuid && i.StudentGuid == personGuid); // Description = db.Classe.Find(ins?.ClasseGuid)?.Name; // Description = Description + " " + db.Filiere.Find(db.Classe.Find(ins?.ClasseGuid)?.FiliereGuid)?.Name; // } //} /// <summary> /// Pour un ComboBox /// </summary> public SearchCard(Guid personGuid, bool isStaff = false) { if (!isStaff) { using (var db = new StationContext()) { PersonGuid = personGuid; FullName = db.Customers.Find(personGuid)?.Person.FullName; PhotoIdentity = db.Customers.Find(personGuid)?.Person.PhotoIdentity; //var anneeScolaireGuid = PedagogyManager.StaticGetStudentDefaultYearGuid(personGuid); //var ins = db.Enrollements.FirstOrDefault(i => i.SchoolYearGuid == anneeScolaireGuid && i.StudentGuid == personGuid); //Description = db.Classes.Find(ins?.ClasseGuid)?.Name; //Description = Description + " " + db.Filieres.Find(db.Classes.Find(ins?.ClasseGuid)?.FiliereGuid)?.Name; } } else { using (var db = new StationContext()) { PersonGuid = personGuid; FullName = db.Staffs.Find(personGuid)?.Person.FullName; PhotoIdentity = db.Staffs.Find(personGuid)?.Person.PhotoIdentity; Description = db.Staffs.Find(personGuid)?.PositionPrincipale; } } }
public async Task <List <FuelCard> > GetFuelCards() { return(await Task.Run(() => { using (var db = new StationContext()) return db.Fuels.Where(f => !f.IsDeleted).ToList().OrderByDescending(c => c.DateAdded).Select(c => new FuelCard(c)).ToList(); })); }
public async Task <double> GetFuelActualPrice(Guid fuelGuid) { return(await Task.Run(() => { using (var db = new StationContext()) return db.Fuels.FindAsync(fuelGuid).Result.Prices.Where(p => p.FromDate <= DateTime.Now).OrderByDescending(p => p.FromDate).First().ActualPrice; })); }
/// <summary> /// Supprimer definitivement un document /// </summary> /// <returns></returns> //[PrincipalPermission(SecurityAction.Demand, Role = Clearances.StaffDelete)] public bool DeleteDocument(Guid documentGuid) { using (var db = new StationContext()) { db.Set <Document>().Remove(db.Set <Document>().Find(documentGuid)); return(db.SaveChanges() > 0); } }
/// <summary> /// Verifie si un recue avec ce numero exist /// </summary> /// <param name="theReference"></param> /// <returns></returns> protected internal static bool SalarySlipExist(string theReference) { using (var mc = new StationContext()) return (mc.Payrolls.Any( s => s.NumeroReference.Equals(theReference, StringComparison.CurrentCultureIgnoreCase))); }
/// <summary> /// Creer Nouvelle Conversation /// </summary> /// <param name="newChat"></param> /// <returns></returns> public bool SaveChat(Chat newChat) { using (var db = new StationContext()) { if (newChat.Persons.Count < 2) { throw new InvalidOperationException("CONVERSATION_MUST_HAVE_AT_LEAST_TWO_PERSONS"); } if (newChat.ChatGuid == Guid.Empty) { newChat.ChatGuid = Guid.NewGuid(); } newChat.DateAdded = DateTime.Now; newChat.AddUserGuid = Guid.Empty; newChat.LastEditUserGuid = Guid.Empty; newChat.LastEditDate = DateTime.Now; //foreach (var talker in newConversation.Persons) //{ // if(talker.PersonGuid==Guid.Empty) // talker.PersonGuid=Guid.NewGuid(); // db.Set<Person>().Add(talker); //} foreach (var talk in newChat.Messages.Where(talk => talk.MessageGuid == Guid.Empty)) { talk.MessageGuid = Guid.NewGuid(); } db.Set <Chat>().Add(newChat); return(db.SaveChanges() > 0); } }
/// <summary> /// /// </summary> /// <param name="depName"></param> /// <returns></returns> public List <Staff> GetDepStaffs(string depName = null) { using (var db = new StationContext()) return(depName == null ? db.Staffs.Where(s => string.IsNullOrEmpty(s.DepartementPrincipale)).OrderBy(s => s.Person.LastName).ToList() : db.Staffs.Where(s => s.DepartementPrincipale == depName).OrderBy(s => s.Person.LastName).ToList()); }
public async Task <List <FuelCard> > GetFuelCards() { return(await Task.Run(() => { using (var db = new StationContext()) return db.Fuels.Where(f => !f.IsDeleted).ToList().Select(f => new FuelCard(f)).ToList(); })); }
/// <summary> /// /// </summary> /// <param name="staffId"></param> /// <returns></returns> public string GetStaffFullName(string staffId) { using (var db = new StationContext()) { return(db.Staffs.First(s => s.Matricule == staffId).Person.FullName); } }
public ColonneCard(string colonne) { Libel = colonne.ToUpper(); using (var db = new StationContext()) Pompes = string.IsNullOrEmpty(colonne) ? db.Pompes.ToList().Where(s => !s.IsDeleted && string.IsNullOrEmpty(s.Colonne)).Select(p=> new PompeCard(p)).ToList() : db.Pompes.ToList().Where(s => !s.IsDeleted && s.Colonne.Equals(colonne, StringComparison.InvariantCultureIgnoreCase)).Select(p=> new PompeCard(p)).ToList(); }
private void GetSTAFFS_LIST ( ) { StaffsList = new List<Staff> (); using (var db = new StationContext()) StaffsList = string.IsNullOrEmpty(DepartementName) ? db.Staffs.Where(s => !s.Person.IsDeleted && string.IsNullOrEmpty(s.DepartementPrincipale)).Include(s => s.Person).ToList() : db.Staffs.Where(s => !s.Person.IsDeleted && s.DepartementPrincipale == DepartementName).Include(s=> s.Person).ToList(); }
/// <summary> /// Les Informtions d'une renumeration /// </summary> /// <param name="salary"></param> public SalaryCard(Salary salary) { SalaryGuid = salary.SalaryGuid; Denomination = salary.Designation; Description = salary.Remuneration + " dhs ("; using (var db = new StationContext()) Description += db.Employments.Find(salary.EmploymentGuid).SalaryRecurrence.GetEnumDescription() + ")"; DateString = salary.StartDate.GetValueOrDefault().ToShortDateString() + " -> " + salary.EndDate.GetValueOrDefault().ToShortDateString(); IsExpiredColor = salary.EndDate.GetValueOrDefault() < DateTime.Today ? "Beige" : "LightGray"; }
/// <summary> /// les donnee concernant une salaire /// </summary> public PayrollCard (Payroll payroll) { PayrollGuid=payroll.PayrollGuid; Designation=payroll.Designation; IsPaid = payroll.IsPaid; TotalSalary = 0; Employment employ; using (var db = new StationContext()) employ=db.Employments.Find(payroll.EmploymentGuid); var payrollStart = employ.SalaryRecurrence == InstallmentRecurrence.Once ? employ.StartDate.GetValueOrDefault() : payroll.PaycheckDate.GetValueOrDefault().AddMonths(-((int)employ.SalaryRecurrence)); switch (employ.PayType) { case PayType.HoursTaught: //TotalSalary=PayrollManager.StaticGetTeachingSalary(employ.StaffGuid, payrollStart, payroll.PaycheckDate, true); RenumerationsCards.Add(new ViewCard { Info1="Heures Enseignées", //Info2=StudyManager.StaticGetHoursTaught(employ.StaffGuid, payrollStart, payroll.PaycheckDate, true).TotalHoursMins(), Info3=TotalSalary.ToString("0.##", CultureInfo.CurrentCulture)+ " dhs" }); break; //case PayType.HoursWorked: // TotalSalary=(payroll.HoursWorked.TotalMinutes*(employ.HourlyPay/60)); // RenumerationsCards.Add(new DataCard { // Info1="Heures Travaillées", // Info2=payroll.HoursWorked.TotalHoursMins(), // Info3=TotalSalary.ToString("0.##", CultureInfo.CurrentCulture)+" dhs" // }); // break; } foreach (var salary in PayrollManager.StaticGetSalaries(employ.EmploymentGuid, payrollStart, payroll.PaycheckDate)) { RenumerationsCards.Add(new ViewCard(salary)); TotalSalary+= salary.Remuneration; } if (payroll.PaycheckDate > DateTime.Today) TotalSalaryString="Estimation: "+TotalSalary.ToString("0.##", CultureInfo.CurrentCulture)+" dhs"; else TotalSalaryString="Total: "+TotalSalary.ToString("0.##", CultureInfo.CurrentCulture)+" dhs"; if (!payroll.IsPaid) return; TotalSalary = payroll.FinalPaycheck; TotalSalaryString ="Paid: "+TotalSalary.ToString("0.##", CultureInfo.CurrentCulture)+" dhs"; NumeroReference="Ref: "+payroll.NumeroReference; Observations = "Finance User ("+payroll.DatePaid.GetValueOrDefault().ToShortDateString()+")"; //+" par "+payroll.PaymentMethode.GetEnumDescription(); YesNoColor ="Blue"; }
public static Task Initialize() { return Task.Run(() => { _database = new RailwayDataModelContainer(); Clients = new ClientContext(); Employees = new EmployeeContext(); Stations = new StationContext(); Seats = new SeatContext(); Tickets = new TicketContext(); TrainWagons = new TrainWagonContext(); Trains = new TrainContext(); Routes = new RouteContext(); VoyageRoutes = new VoyageRouteContext(); Voyages = new VoyageContext(); Wagons = new WagonContext(); WagonSeats = new WagonSeatContext(); Clients.Repository = _database.ClientSet; Employees.Repository = _database.EmployeeSet; Stations.Repository = _database.StationSet; Seats.Repository = _database.SeatSet; Tickets.Repository = _database.TicketSet; TrainWagons.Repository = _database.TrainWagonSet; Trains.Repository = _database.TrainSet; VoyageRoutes.Repository = _database.VoyageRouteSet; Routes.Repository = _database.RouteSet; Voyages.Repository = _database.VoyageSet; Wagons.Repository = _database.WagonSet; WagonSeats.Repository = _database.WagonSeatSet; DataBase.Database.Connection.OpenAsync(); }); }