Ejemplo n.º 1
0
        /// <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;
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// La list des Documents d'une Personne
 /// </summary>
 /// <param name="personGuid"></param>
 /// <param name="maxResult"></param>
 /// <returns></returns>
 public IEnumerable GetPersonDocuments(Guid personGuid, int maxResult = 7)
 {
     using (var db = new StationContext()) {
         return (db.Set<Person>().Find(personGuid).Documents).Select(
                 d => new Document {DocumentGuid = d.DocumentGuid, DocumentName = d.DocumentName, Description = d.Description, FileType = d.FileType }).OrderBy(d=> d.DateAdded);                
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Confirmer paiement d'un salaire
        /// </summary>
        /// <param name="payrollGuid"></param>
        /// <param name="finalPaycheck"></param>
        /// <param name="numeroReference"></param>
        /// <param name="totalHoursWorked"></param>
        /// <returns></returns>
        /// <exception cref="InvalidOperationException"></exception>
        public bool Paycheck(Guid payrollGuid, double? finalPaycheck = null, string numeroReference = null, TimeSpan? totalHoursWorked = null)
        {           
            using (var db = new StationContext()) {
                var payroll = db.Payrolls.Find(payrollGuid);
                if(payroll==null)
                    throw new InvalidOperationException("PAYROLL_REFERENCE_NOT_FOUND");
                
                if(payroll.IsPaid)
                    throw new InvalidOperationException("PAYCHECK_ALREADY_PAID");

                if(!string.IsNullOrEmpty(numeroReference) && SalarySlipExist(numeroReference))
                    throw new InvalidOperationException("PAYSLIP_REFERENCE_DUPLICATE");

                if(totalHoursWorked!=null)
                    payroll.HoursWorked = (TimeSpan) totalHoursWorked;

                if(finalPaycheck==null)
                    finalPaycheck=(new PayrollCard(payroll)).TotalSalary;

                payroll.FinalPaycheck    = (double) finalPaycheck;
                payroll.IsPaid           = true;
                payroll.IsPaidTo         = Guid.Empty;
                payroll.DatePaid         = DateTime.Now;
                payroll.NumeroReference  = string.IsNullOrEmpty(numeroReference) ? GetNewSalarySlipRef() : numeroReference;

                payroll.LastEditDate     =DateTime.Now;
                payroll.LastEditUserGuid =Guid.Empty;

                db.Payrolls.Attach(payroll);
                db.Entry(payroll).State=EntityState.Modified;

                return db.SaveChanges()>0;
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Represente un enseignant, proff, staff, qui a la possibilite de se connecter a l'Eschool
 /// </summary>
 /// <param name="document"></param>
 /// <returns></returns>
 //[PrincipalPermission(SecurityAction.Demand, Role = Clearances.StaffWrite)]
 public bool SaveDocument (Document document) {                      
     using (var db = new StationContext()) {
         if(document.DocumentGuid==Guid.Empty)
             document.DocumentGuid=Guid.NewGuid();
         
         db.Set<Document>().Add(document);
         return db.SaveChanges()>0;
     }
 }
Ejemplo n.º 5
0
        public async Task<bool> Put(Fuel myFuel)
        {
            using (var db = new StationContext())
            {
                myFuel.LastEditDate = DateTime.Now;

                db.Fuels.Attach(myFuel);
                db.Entry(myFuel).State = EntityState.Modified;
                return await db.SaveChangesAsync() > 0;
            }
        }
Ejemplo n.º 6
0
        public bool Put(Pompe myPompe)
        {
            using (var db = new StationContext())
            {
                myPompe.LastEditDate = DateTime.Now;

                db.Pompes.Attach(myPompe);
                db.Entry(myPompe).State = EntityState.Modified;
                return db.SaveChanges() > 0;
            }
        }
Ejemplo n.º 7
0
        public bool Put(FuelPrelevement myPrelevement)
        {
            using (var db = new StationContext())
            {
                myPrelevement.LastEditDate = DateTime.Now;

                db.Set<FuelPrelevement>().Attach(myPrelevement);
                db.Entry(myPrelevement).State = EntityState.Modified;
                return db.SaveChanges() > 0;
            }
        }
Ejemplo n.º 8
0
        public bool Put(Oil myOil)
        {
            using (var db = new StationContext())
            {
                myOil.LastEditDate = DateTime.Now;

                db.Oils.Attach(myOil);
                db.Entry(myOil).State = EntityState.Modified;
                return db.SaveChanges() > 0;
            }
        }
Ejemplo n.º 9
0
        public async Task<bool> Post(FuelDelivery fuelDelivery)
        {
            using (var db = new StationContext())
            {
                if (fuelDelivery.FuelDeliveryGuid == Guid.Empty) fuelDelivery.FuelDeliveryGuid = Guid.NewGuid();

                fuelDelivery.DateAdded = DateTime.Now;
                fuelDelivery.LastEditDate = DateTime.Now;

                db.FuelDeliverys.Add(fuelDelivery);
                return await db.SaveChangesAsync() > 0;
            }
        }
Ejemplo n.º 10
0
        public async Task<bool> Post(Citerne myCiternes)
        {
            using (var db = new StationContext())
            {                
                if (myCiternes.CiterneGuid == Guid.Empty) myCiternes.CiterneGuid = Guid.NewGuid();

                myCiternes.DateAdded = DateTime.Now;
                myCiternes.LastEditDate = DateTime.Now;

                db.Citernes.Add(myCiternes);
                return await db.SaveChangesAsync() > 0;
            }
        }       
Ejemplo n.º 11
0
        public bool UpdateStaff(Staff mStaff)
        {
            using (var db = new StationContext())
            {
                db.Staffs.Attach(mStaff);
                db.Entry(mStaff).State = EntityState.Modified;

                db.Set<Person>().Attach(mStaff.Person);
                db.Entry(mStaff.Person).State = EntityState.Modified;

                return db.SaveChanges() > 0;
            }
        }
Ejemplo n.º 12
0
        public bool Post(OilDelivery myDelivery)
        {
            using (var db = new StationContext())
            {
                if (myDelivery.OilDeliveryGuid == Guid.Empty) myDelivery.OilDeliveryGuid = Guid.NewGuid();

                myDelivery.DateAdded = DateTime.Now;
                myDelivery.LastEditDate = DateTime.Now;

                db.OilDeliveries.Add(myDelivery);
                return db.SaveChanges() > 0;
            }
        }
Ejemplo n.º 13
0
        public bool Post(Oil myOil)
        {
            using (var db = new StationContext())
            {
                if (myOil.OilGuid == Guid.Empty) myOil.OilGuid = Guid.NewGuid();

                myOil.DateAdded = DateTime.Now;
                myOil.LastEditDate = DateTime.Now;

                db.Oils.Add(myOil);
               return db.SaveChanges() > 0;              
            }
        }
Ejemplo n.º 14
0
        public async Task<bool> Delete(Guid fuelGuid)
        {
            using (var db = new StationContext())
            {
                var myObject = await db.Fuels.FindAsync(fuelGuid);

                if (myObject == null) throw new InvalidOperationException("FUEL_NOT_FOUND");

                myObject.LastEditDate = DateTime.Now;
                myObject.IsDeleted = true;

                db.Fuels.Attach(myObject);
                db.Entry(myObject).State = EntityState.Modified;
                return await db.SaveChangesAsync() > 0;
            }
        }
Ejemplo n.º 15
0
        public async Task<bool> AddStaff(Staff myStaff)
        {
            using (var db = new StationContext())
            {
                if (myStaff.StaffGuid == Guid.Empty)
                    myStaff.StaffGuid = Guid.NewGuid();
                if (myStaff.Person.PersonGuid == Guid.Empty)
                    myStaff.Person.PersonGuid = Guid.NewGuid();

                await myStaff.Person.Validate();

                db.Set<Person>().Add(myStaff.Person);
                db.Staffs.Add(myStaff);
                return await db.SaveChangesAsync() > 0;
            }
        }
Ejemplo n.º 16
0
        public bool Post(Pompe myPompe)
        {
            using (var db = new StationContext())
            {
                if (!db.Citernes.Any(f => f.CiterneGuid == myPompe.CiterneGuid))
                    throw new InvalidOperationException("CITERNE_REFERENCE_NOT_FOUND");
                

                if (myPompe.PompeGuid == Guid.Empty) myPompe.PompeGuid = Guid.NewGuid();

                myPompe.DateAdded = DateTime.Now;
                myPompe.LastEditDate = DateTime.Now;

                db.Pompes.Add(myPompe);
                return db.SaveChanges() > 0;
            }
        }
Ejemplo n.º 17
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="myCustomer"></param>
        /// <returns></returns>
        //[PrincipalPermission(SecurityAction.Demand, Role = SecurityClearances.StaffWrite)]
        public bool UpdateCustomer(Customer myCustomer)
        {
            using (var db = new StationContext())
            {
                // ReSharper disable once PossibleNullReferenceException
                var userTrace = (Guid)Membership.GetUser().ProviderUserKey;                
                myCustomer.LastEditDate = DateTime.Now;
                myCustomer.LastEditUserGuid = userTrace;

                db.Customers.Attach(myCustomer);
                db.Entry(myCustomer).State = EntityState.Modified;

                db.Set<Person>().Attach(myCustomer.Person);
                db.Entry(myCustomer.Person).State = EntityState.Modified;

                return db.SaveChanges() > 0;
            }
        }
Ejemplo n.º 18
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="transactionGuid"></param>
        /// <returns></returns>
        public bool CancelTransaction(Guid transactionGuid)
        {
            using (var db = new StationContext())
            {
                var theTransaction = db.Transactions.Find(transactionGuid);
                if (theTransaction == null) throw new InvalidOperationException("CAN_NOT_FIND_REFERENCE_TRANSACTION");

                theTransaction.IsDeleted = true;
                theTransaction.DeleteDate = DateTime.Now;
                theTransaction.DeleteUserGuid = Guid.Empty;

                theTransaction.LastEditDate = DateTime.Now;
                theTransaction.LastEditUserGuid = Guid.Empty;

                db.Transactions.Attach(theTransaction);
                db.Entry(theTransaction).State = EntityState.Modified;
                return db.SaveChanges() > 0;
            }
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Annuler un Paiement d'un salaire
        /// </summary>
        /// <param name="payrollGuid"></param>
        public bool CancelPaycheck (Guid payrollGuid) {
            using (var db = new StationContext()) {
                var payroll = db.Payrolls.Find(payrollGuid);
                if(payroll==null)
                    throw new InvalidOperationException("PAYROLL_REFERENCE_NOT_FOUND");
                
                payroll.IsPaid           =false;
                payroll.IsPaidTo         =Guid.Empty;
                payroll.DatePaid         =DateTime.Now;
                payroll.NumeroReference  = string.Empty;

                payroll.LastEditDate     =DateTime.Now;
                payroll.LastEditUserGuid =Guid.Empty;

                db.Payrolls.Attach(payroll);
                db.Entry(payroll).State=EntityState.Modified;

                return db.SaveChanges()>0;
            }
        }
Ejemplo n.º 20
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;
            }
        }        
Ejemplo n.º 21
0
        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;
            }
        }
Ejemplo n.º 22
0
        /// <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;
            }
        }
Ejemplo n.º 23
0
        /// <summary>
        /// Envoyer Un Chat
        /// </summary>
        /// <param name="newMessage"></param>
        /// <returns></returns>
        public bool PushChat (Message newMessage) {
            using (var db = new StationContext()) {
                if(db.Set<Person>().Find(newMessage.SenderGuid)==null)
                    throw new InvalidOperationException("SENDER_REFERENCE_NOT_FOUND");
                if(newMessage.MessageGuid==Guid.Empty)
                    newMessage.MessageGuid=Guid.NewGuid();
                if(db.Set<Chat>().Find(newMessage.ChatGuid)==null)
                    throw new InvalidOperationException("CONVERSATION_REFERENCE_NOT_FOUND");

                newMessage.DateAdded        =DateTime.Now;
                newMessage.AddUserGuid      = Guid.Empty;
                newMessage.LastEditUserGuid = Guid.Empty;
                newMessage.LastEditDate     =DateTime.Now;
                
                if (newMessage.Attachement == null) return db.SaveChanges() > 0;

                if(newMessage.Attachement.DocumentGuid==Guid.Empty)
                    newMessage.Attachement.DocumentGuid=Guid.NewGuid();
                db.Set<Document>().Add(newMessage.Attachement);
                db.Set<Message>().Add(newMessage);

                return db.SaveChanges()>0;
            }
        }
Ejemplo n.º 24
0
 public async Task<Oil> Get(Guid oilGuid)
 {
     using (var db = new StationContext())
         return await db.Oils.FindAsync(oilGuid);
 }
Ejemplo n.º 25
0
 internal async static Task<List<OilPrelevement>> GetPrelevemnts(List<Guid> oilsGuids, DateTime fromDate, DateTime toDate)
 {
    return await Task.Run(() => {
         using (var db = new StationContext()) {
         var prelevements = new List<OilPrelevement>();
         foreach (var oilGuid in oilsGuids)
             prelevements.AddRange(db.Oils.Find(oilGuid)
                     .Prelevements.Where(
                         p => p.DatePrelevement >= fromDate &&
                              p.DatePrelevement <= toDate && !p.IsDeleted));
         return prelevements;
         }});
 }
Ejemplo n.º 26
0
        internal async static Task<List<OilDelivery>> GetDeliveries(List<Guid> oilsGuids, DateTime fromDate, DateTime toDate)
        {
            return await Task.Run(() => {
                using (var db = new StationContext())
                {
                    var deliveries = new List<OilDelivery>();

                    foreach (var oilGuid in oilsGuids)
                        deliveries.AddRange(
                            db.Oils.Find(oilGuid)
                                .Deliveries.Where(
                                    p => p.DeliveryDate.GetValueOrDefault().Date >= fromDate &&
                                         p.DeliveryDate.GetValueOrDefault().Date <= toDate && !p.IsDeleted));
                    return deliveries;
                }});
        }
Ejemplo n.º 27
0
        internal static int StaticGetOilBalance(Guid oilGuid)
        {
            using (var db = new StationContext())
                try
                {
                    var stocks = db.Oils.Find(oilGuid).InitialStock + db.Oils.Find(oilGuid)?.Deliveries.Where(d =>!d.IsDeleted).Sum(s => s.QuantityDelivered) ?? 0;

                    var solds = db.Oils.Find(oilGuid)?.Prelevements.Where(p =>!p.IsDeleted).Sum(p => p.Result) ?? 0;

                    return (stocks - solds);
                }
                catch (Exception exception)
                {
                    DebugHelper.WriteException(exception);
                    return 0;
                }
        }
Ejemplo n.º 28
0
 public async Task<List<OilDeliveryCard>> GetOilDeliveries(List<Guid> oilsGuids, DateTime fromDate, DateTime toDate)
 {
     return await Task.Run(() => {
         using (var db = new StationContext())
         {
             var deliveries = new List<OilDelivery>();
             foreach (var oil in db.Oils.Where(f => oilsGuids.Contains(f.OilGuid)))
                 deliveries.AddRange(oil.Deliveries.Where(p => p.DeliveryDate.GetValueOrDefault().Date >= fromDate && p.DeliveryDate.GetValueOrDefault().Date <= toDate && !p.IsDeleted));
             return deliveries.OrderByDescending(p => p.DeliveryDate).Select(p => new OilDeliveryCard(p)).ToList();
         }});
 }
Ejemplo n.º 29
0
 public IEnumerable GetOilDeliveries(Guid oilGuid)
 {
     using (var db = new StationContext())
         return db.Oils.Find(oilGuid)?.Deliveries.Where(d =>!d.IsDeleted).OrderByDescending(s => s.DateAdded).ToList().Select(s => new OilDeliveryCard(s)).ToList();
 }
Ejemplo n.º 30
0
 internal static OilPrelevement StaticGetLastPrelevement(Guid oilGuid)
 {
     using (var db = new StationContext())
         return db.Oils.Find(oilGuid).Prelevements.Where(p =>!p.IsDeleted).OrderByDescending(p => p.DatePrelevement).FirstOrDefault() ??
             new OilPrelevement { Meter = db.Oils.Find(oilGuid).InitialStock};
 }