Exemplo n.º 1
0
        /// <summary>
        /// Les details d'un Staff
        /// </summary>
        /// <param name="staffObject"></param>
        public StaffDetails (Staff staffObject) {

            InitializeComponent();

            new Task(() => Dispatcher.BeginInvoke(new Action(() =>
            {
                _TITLE_TEXT.Text               = staffObject.Person.FullName;
                _STAFF_DOCS.PersonGuid         =staffObject.Person.PersonGuid;
                _STAFF_CARD.StaffGuid          =staffObject.StaffGuid;
                _USER_CARD.ProfileGuid         =staffObject.StaffGuid;
                _USER_USPACES.ProfileGuid      =staffObject.StaffGuid;
            }))).Start();
        }
Exemplo n.º 2
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;
            }
        }
Exemplo n.º 3
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;
            }
        }
Exemplo n.º 4
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;
            //}
        }