Esempio n. 1
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;
            }
        }
Esempio n. 2
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;
     }
 }
Esempio n. 3
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;
            }
        }
Esempio n. 4
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;
            }
        }
Esempio n. 5
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;
            }
        }
Esempio n. 6
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;              
            }
        }
Esempio n. 7
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;
            }
        }
Esempio n. 8
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;
            }
        }
Esempio n. 9
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;
            }
        }
Esempio n. 10
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;
            }
        }
Esempio n. 11
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;
            }
        }
Esempio n. 12
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;
            }
        }        
Esempio n. 13
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;
            }
        }
Esempio n. 14
0
 /// <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;               
     }
 }
Esempio n. 15
0
        /// <summary>
        /// Modifier les information d'un employement
        /// </summary>
        /// <param name="employ"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public bool UpdateEmployment(Employment employ)
        {
            if (string.IsNullOrEmpty(employ.Position))                                        throw new InvalidOperationException("POSITION_CAN_NOT_BE_EMPTY");
            if (employ.StartDate > employ.EndDate)                                            throw new InvalidOperationException("START_DATE_SUPERIOR_TO_END_DATE");
            using (var db = new StationContext()) if (db.Staffs.Find(employ.StaffGuid) == null) throw new InvalidOperationException("STAFF_REFERENCE_NOT_FOUND");

            using (var db = new StationContext())
            {
                var newEmploy = db.Employments.Find(employ.EmploymentGuid);
                if (newEmploy == null)                                                        throw new InvalidOperationException("EMPLOYEMENT_REFERENCE_NOT_FOUND");

                //todo cancel Employ 
                newEmploy.Position         = employ.Position;
                newEmploy.Category         = employ.Category;
                newEmploy.Project          = employ.Project;
                newEmploy.Grade            = employ.Grade;
                newEmploy.Departement      = employ.Departement;
                newEmploy.Division         = employ.Division;
                newEmploy.ReportTo         = employ.ReportTo;
                //newEmploy.SalaryRecurrence = employ.SalaryRecurrence;
                //newEmploy.StartDate        = employ.StartDate;
                //newEmploy.EndDate          = employ.EndDate;
                newEmploy.Description      = employ.Description;

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

                db.Employments.Attach(newEmploy);
                db.Entry(newEmploy).State = EntityState.Modified;

                return db.SaveChanges() > 0;
            }
        }
Esempio n. 16
0
 /// <summary>
 /// Supprimer un chat
 /// </summary>
 /// <param name="chatGuid"></param>
 /// <returns></returns>
 public bool DeleteChat (Guid chatGuid) {
     using (var db = new StationContext()) {
         var oldConversation = db.Set<Chat>().Find(chatGuid);
         oldConversation.IsDeleted=true;
         oldConversation.DeleteUserGuid=Guid.Empty;
         db.Set<Chat>().Attach(oldConversation);
         db.Entry(oldConversation).State=EntityState.Modified;
         return db.SaveChanges()>0;
     }
 }
Esempio n. 17
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;
            }
        }
Esempio n. 18
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="messageGuid"></param>
 /// <param name="markRead"></param>
 /// <returns></returns>
 public Conversation GetMessage(Guid messageGuid, bool markRead = true)
 {
     using (var db = new StationContext())
     {              
         var oldMessage = db.Conversations.Find(messageGuid);
         if (oldMessage == null) return null;
        
         oldMessage.IsRead=true;
         oldMessage.LastEditDate=DateTime.Now;
         db.Conversations.Attach(oldMessage);
         db.Entry(oldMessage).State=EntityState.Modified;
         db.SaveChanges();
         return oldMessage;
     }
 }
Esempio n. 19
0
        /// <summary>
        /// Ajouter un Payroll
        /// </summary>
        /// <returns></returns>
        protected internal static bool StaticAddPayRoll(Payroll payRoll)
        {
            if (PayRollExist(payRoll)) return true;
 
            using (var db = new StationContext())
            {
                if (payRoll.PayrollGuid == Guid.Empty) payRoll.PayrollGuid = Guid.NewGuid();

                payRoll.DateAdded        = DateTime.Now;
                payRoll.AddUserGuid      = Guid.Empty;
                payRoll.LastEditDate     = DateTime.Now;
                payRoll.LastEditUserGuid = Guid.Empty;

                db.Payrolls.Add(payRoll);
                return db.SaveChanges() > 0;
            }
        }
Esempio n. 20
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="salary"></param>
        /// <returns></returns>
        protected internal static bool StaticAddSalary(Salary salary)
        {
            if (SalaryExist(salary)) return true;
            if (string.IsNullOrEmpty(salary.Designation)) throw new InvalidOperationException("DESIGNATION_CAN_NOT_BE_EMPTY");
            if (salary.StartDate > salary.EndDate)        throw new InvalidOperationException("START_DATE_SUPERIOR_TO_END_DATE");

            Employment emp;
            using (var db = new StationContext()) emp = db.Employments.Find(salary.EmploymentGuid);

            if (emp == null) throw new InvalidOperationException("EMPLOYEMENT_REFERENCE_NOT_FOUND");
            if ((salary.StartDate < emp.StartDate) || (salary.EndDate > emp.EndDate)) throw new InvalidOperationException("DATES_CAN_NOT_BE_OUT_OF_EMPLOYMENT_BOUNDRIES");

            using (var db = new StationContext())
            {
                if (salary.SalaryGuid == Guid.Empty) salary.SalaryGuid = Guid.NewGuid();
                if (salary.Description == string.Empty) salary.Description = salary.Designation;

                salary.DateAdded        = DateTime.Now;
                salary.AddUserGuid      = Guid.Empty;
                salary.LastEditDate     = DateTime.Now;
                salary.LastEditUserGuid = Guid.Empty;

                db.Salaries.Add(salary);
                return db.SaveChanges() > 0;
            }
        }
Esempio n. 21
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="customerGuid"></param>
        /// <returns></returns>
        //[PrincipalPermission(SecurityAction.Demand, Role = SecurityClearances.StaffDelete)]
        public bool Delete(Guid customerGuid)
        {
            using (var db = new StationContext())
            {
                var theMan = db.Customers.Find(customerGuid);

                Guard.WhenArgument(theMan, "CAN_NOT_FIND_STAFF_REFERENCE").IsNull().Throw();

                theMan.Person.DeleteDate = DateTime.Now;
                theMan.Person.IsDeleted = true;
                // ReSharper disable once PossibleNullReferenceException
                theMan.Person.DeleteUserGuid = (Guid)Membership.GetUser().ProviderUserKey;

                db.Customers.Attach(theMan);
                db.Entry(theMan).State = EntityState.Modified;
                return db.SaveChanges() > 0;
            }
        }
Esempio n. 22
0
        public bool DeleteStaff(Guid staffGuid)
        {
            using (var db = new StationContext())
            {
                var theMan = db.Staffs.Find(staffGuid);

                if (theMan == null)
                    throw new InvalidOperationException("CAN_NOT_FIND_STAFF_REFERENCE");

                theMan.Person.DeleteDate = DateTime.Now;
                theMan.Person.IsDeleted = true;
                theMan.Person.DeleteUserGuid = Guid.Empty;

                db.Staffs.Attach(theMan);
                db.Entry(theMan).State = EntityState.Modified;
                return db.SaveChanges() > 0;
            }
        }
Esempio n. 23
0
        /// <summary>
        /// Modifier les information d'un salaire
        /// </summary>
        /// <param name="salary"></param>
        /// <exception cref="NotImplementedException"></exception>
        public bool CancelSalary(Salary salary)
        {
            if (string.IsNullOrEmpty(salary.Designation)) throw new InvalidOperationException("DESIGNATION_CAN_NOT_BE_EMPTY");
            if (salary.StartDate > salary.EndDate) throw new InvalidOperationException("START_DATE_SUPERIOR_TO_END_DATE");
            if (salary.EndDate < DateTime.Today)   throw new InvalidOperationException("END_DATE_CAN_NOT_BE_LESS_THAN_TODAY");

            Employment emp;
            using (var db = new StationContext()) emp = db.Employments.Find(salary.EmploymentGuid);
            if (emp == null) throw new InvalidOperationException("EMPLOYEMENT_REFERENCE_NOT_FOUND");
            if ((salary.StartDate < emp.StartDate) || (salary.EndDate > emp.EndDate)) throw new InvalidOperationException("DATES_CAN_NOT_BE_OUT_OF_EMPLOYMENT_BOUNDRIES");

            using (var db = new StationContext())
            {
                var newSalary = db.Salaries.Find(salary.SalaryGuid);
                if (newSalary == null) throw new InvalidOperationException("SALARY_REFERENCE_NOT_FOUND");

                newSalary.EndDate      = salary.EndDate;
                newSalary.Description  = salary.Description;

                var user = Membership.GetUser();
                if (user == null) throw new SecurityException("USER_CAN_NOT_DETERMINED");

                // ReSharper disable once PossibleNullReferenceException
                newSalary.LastEditUserGuid = (Guid)user.ProviderUserKey;
                newSalary.LastEditDate = DateTime.Now;

                db.Salaries.Attach(newSalary);
                db.Entry(newSalary).State = EntityState.Modified;
                return db.SaveChanges() > 0;
            }
        }
Esempio n. 24
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;
            }
        }
Esempio n. 25
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;
            }
        }
Esempio n. 26
0
        /// <summary>
        /// Authenticate l'utilisateur
        /// </summary>
        /// <param name="userName">Pseudo</param>
        /// <param name="userPassword">Mot de Passe</param>
        /// <returns>True si l'operation success</returns>
        /// <exception cref="SecurityException">CAN_NOT_FIND_USER</exception>
        public bool Authenticate(string userName, string userPassword)
        {
            //foreach (var user in Membership.GetAllUsers())
            //    Membership.DeleteUser(user.ToString());


            if (Membership.GetAllUsers().Count == 0)
            {
                MembershipCreateStatus status;
                Membership.CreateUser(
                    "admin",
                    "admin00.",
                    "*****@*****.**",
                    "admin",
                    "admin",
                    true,
                    new Guid("53f258a3-f931-4975-b6ec-17d26aa95848"),
                    out status);
                if (status == MembershipCreateStatus.Success)
                {
                    using (var db = new StationContext())
                    {
                        var shadow = new Staff
                        {
                            StaffGuid = new Guid("53f258a3-f931-4975-b6ec-17d26aa95848"),
                            Person = new Person
                            {
                                PersonGuid = Guid.NewGuid(),
                                FirstName = "Admin",
                                LastName = "Admin"
                            }
                        };
                        if (db.Staffs.Find(new Guid("53f258a3-f931-4975-b6ec-17d26aa95848")) == null)
                            db.Staffs.Add(shadow);
                        db.SaveChanges();

                        foreach (var adminClear in Enum.GetValues(typeof(AdminClearances)).Cast<object>().Where(adminClear => !Roles.RoleExists(adminClear.ToString())))
                            Roles.CreateRole(adminClear.ToString());

                        foreach (var adminClear in Enum.GetValues(typeof(AdminClearances)).Cast<object>().Where(adminClear => !Roles.IsUserInRole("admin", adminClear.ToString())))
                            Roles.AddUserToRole("admin", adminClear.ToString());

                        if (!Roles.RoleExists(UserSpace.AdminSpace.ToString()))
                            Roles.CreateRole(UserSpace.AdminSpace.ToString());

                        if (!Roles.IsUserInRole("admin", UserSpace.AdminSpace.ToString()))
                            Roles.AddUserToRole("admin", UserSpace.AdminSpace.ToString());

                    }
                }
            }


            try
            {
                if (!Membership.ValidateUser(userName, userPassword))
                    return false;

                var user = Membership.GetUser(userName);
                if (user == null)
                    throw new SecurityException("CAN_NOT_FIND_USER");

                var identity = new GenericIdentity(user.UserName);
                var principal = new RolePrincipal(identity);
                Thread.CurrentPrincipal = principal;
                return true;
            }
            catch (SqlException sqlException)
            {
                DebugHelper.WriteException(sqlException);
                throw;
            }
            catch (Exception ex)
            {
                DebugHelper.WriteException(ex);
                return false;
            }
            //try
            //{
            //    //foreach (var allUser in Membership.GetAllUsers())
            //    //    Membership.DeleteUser(allUser.ToString());

            //    //using (var db = new StationContext())
            //    //{
            //    //    if (db.Database.Exists())
            //    //    {
            //    //        db.Database.Delete();
            //    //        db.Database.Create();
            //    //    }
            //    //}

            //    if (!Membership.ValidateUser(userName, userPassword))
            //        {
            //            if (Membership.GetAllUsers().Count != 0) return false;
            //            MembershipCreateStatus status;
            //            Membership.CreateUser(
            //                "admin",
            //                "admin00.",
            //                "*****@*****.**",
            //                "admin",
            //                "admin",
            //                true,
            //                new Guid("53f258a3-f931-4975-b6ec-17d26aa95848"),
            //                out status);
            //            if (status != MembershipCreateStatus.Success) return false;
            //            Roles.CreateRole(AdminClearances.SuperUser.ToString());
            //            Roles.CreateRole(AdminClearances.StaffWrite.ToString());
            //            Roles.CreateRole(UserSpace.AdminSpace.ToString());

            //            Roles.AddUserToRole("admin", AdminClearances.SuperUser.ToString());
            //            Roles.AddUserToRole("admin", AdminClearances.StaffWrite.ToString());
            //            Roles.AddUserToRole("admin", UserSpace.AdminSpace.ToString());
            //            return false;
            //        }

            //    var user = Membership.GetUser(userName);
            //    if (user == null)
            //        throw new SecurityException("CAN_NOT_FIND_USER");

            //    var identity = new GenericIdentity(user.UserName);
            //    var principal = new RolePrincipal(identity);
            //    Thread.CurrentPrincipal = principal;
            //    return true;
            //}
            //catch (SqlException sqlException)
            //{
            //    DebugHelper.WriteException(sqlException);
            //    throw;
            //}
            //catch (Exception ex)
            //{
            //    DebugHelper.WriteException(ex);
            //    return false;
            //}
        }
Esempio n. 27
0
        /// <summary>
        /// Envoyer Un Message
        /// </summary>
        /// <param name="conversation"></param>
        /// <returns></returns>
        public bool SendMessage(Conversation conversation)
        {
            using (var db = new StationContext()) {
                if(db.Set<Person>().Find(conversation.SenderGuid)==null)
                    throw new InvalidOperationException("SENDER_REFERENCE_NOT_FOUND");
                if (conversation.MessageGuid == Guid.Empty) conversation.MessageGuid = Guid.NewGuid();
                if(conversation.RecipientGuid==conversation.SenderGuid)
                    throw new InvalidOperationException("MESSAGE_SENDER_CAN_NOT_EGUAL_RECIPIENT");

                switch (conversation.MessageType)
                {
                    case MessageType.Personal:                      
                        if(db.Set<Person>().Find(conversation.RecipientGuid)==null)
                            throw new InvalidOperationException("RECIPIENT_REFERENCE_NOT_FOUND");                      
                        break;

                    case MessageType.Email:
                        if(string.IsNullOrEmpty(conversation.RecipientEmail))
                            conversation.RecipientEmail=db.Set<Person>().Find(conversation.RecipientGuid).EmailAdress;
                        if( !InputHelper.IsValidEmail(conversation.RecipientEmail))
                            throw new InvalidOperationException("RECIPIENT_EMAIL_INVALID");
                        


                        var newMail = new MailMessage();                        
                        newMail.To.Add(new MailAddress(conversation.RecipientEmail));
                        newMail.Subject  = conversation.Subject;
                        newMail.Body     = conversation.Content;

                        if (EmailHelper.SendMailByGmail(newMail))
                        {
                            conversation.DateAdded=DateTime.Now;
                            conversation.LastEditDate=DateTime.Now;
                            db.Conversations.Add(conversation);
                            return db.SaveChanges()>0;
                        }
                        return false;
                                                                  
                    //case MessageType.ToClasse:                       
                    //    if(db.Classes.Find(conversation.RecipientGuid)==null)
                    //        throw new InvalidOperationException("CLASSE_REFERENCE_NOT_FOUND");
                    //    break;
                }
                
                conversation.DateAdded    =DateTime.Now;
                conversation.LastEditDate =DateTime.Now;

                db.Conversations.Add(conversation);
                if (conversation.Attachement != null)                
                   db.Set<Document>().Add(conversation.Attachement);
                return db.SaveChanges()>0;
            }
        }
Esempio n. 28
0
 /// <summary>
 /// Supprimer un Message
 /// </summary>
 /// <param name="messageGuid"></param>
 /// <returns></returns>
 public bool DeleteMessage (Guid messageGuid) {
     using (var db = new StationContext())
     {
         var oldMessage = db.Conversations.Find(messageGuid);
         oldMessage.IsDeleted = true;
         oldMessage.DeleteUserGuid = Guid.Empty;
         db.Conversations.Attach(oldMessage);
         db.Entry(oldMessage).State=EntityState.Modified;
         return db.SaveChanges()>0;               
     }
 }
Esempio n. 29
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;
            }
        }
Esempio n. 30
0
        /// <summary>
        /// Ajouter Un Employement Pour un Staff
        /// </summary>
        /// <param name="employ"></param>
        /// <returns>True pour Success</returns>
        public bool AddEmployment(Employment employ)
        {
            if (string.IsNullOrEmpty(employ.Position)) throw new InvalidOperationException("POSITION_CAN_NOT_BE_EMPTY");
            if (employ.StartDate > employ.EndDate)     throw new InvalidOperationException("START_DATE_SUPERIOR_TO_END_DATE");
            using (var db = new StationContext()) if (db.Staffs.Find(employ.StaffGuid) == null) throw new InvalidOperationException("STAFF_REFERENCE_NOT_FOUND");

            using (var db = new StationContext())
            {
                if (employ.EmploymentGuid == Guid.Empty) employ.EmploymentGuid = Guid.NewGuid();

                employ.DateAdded        = DateTime.Now;
                employ.AddUserGuid      = Guid.Empty;
                employ.LastEditDate     = DateTime.Now;
                employ.LastEditUserGuid = Guid.Empty;
                
                db.Employments.Add(employ);

                if (db.SaveChanges() <= 0)
                    return false;

                foreach (var payRoll in PayRollHelper.GeneratePayRolls(employ))
                    StaticAddPayRoll(payRoll);
                return true;
            }
        }