示例#1
0
        public override System.Web.Security.MembershipUser GetUser(object providerUserKey, bool userIsOnline)
        {
            BuildingEntities db;
            User             user;
            MembershipUser   result = null;
            int id;

            if (providerUserKey is int)
            {
                id = (int)providerUserKey;
            }
            else
            {
                id = providerUserKey.ToString().ToInt();
            }

            using (db = new BuildingEntities())
            {
                user = db.Users.FirstOrDefault(val => val.ID == id && !val.Deleted);
                if (user != null)
                {
                    result = ConvertUser(user);
                }
            }
            return(result);
        }
示例#2
0
        public string GetPhone(BuildingEntities db)
        {
            string result = null;
            var    cp     = db.ContactPersons.Find(val => val.ContractorID == this.ID && val.IsMain).ToList().FirstOrDefault(val => val.EntityState != System.Data.EntityState.Deleted);

            if (cp != null)
            {
                result = cp.Phone;
            }
            if (result.IsNotNullOrEmpty())
            {
                return(result);
            }

            if (TypeID == (int)BuildingEntities.ContractorTypesEnum.Company)
            {
                LegalDetail details = this.LegalDetails.FirstOrDefault();
                return(details != null ? details.Phone : string.Empty);
            }
            else
            {
                PhysicalDetail details = this.PhysicalDetails.FirstOrDefault();
                return(details != null ? details.Phone : string.Empty);
            }
        }
示例#3
0
        public override bool ValidateUser(string username, string password)
        {
            BuildingEntities db;
            User             user;
            bool             result;

            password = password.ToSha1Base64String();

            using (db = new BuildingEntities())
            {
                user = db.Users.FirstOrDefault(val => val.Login == username && (val.Password == password || val.Password == string.Empty) && !val.Blocked && !val.Deleted);
                if (user != null && user.RoleID == (int)RolesEnum.Employee)
                {
                    user.EmployeeReference.Load();
                    Employee e = user.Employee;
                    user = e == null || e.Archived || e.Deleted ? null : user;
                }

                if (user != null && user.Password.IsNullOrEmpty())
                {
                    user.Password = password;
                    db.SaveChanges();
                }
            }
            result = user != null;
            return(result);
        }
示例#4
0
        public override System.Web.Security.MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out System.Web.Security.MembershipCreateStatus status)
        {
            BuildingEntities db;
            User             user;
            int count;

            System.Web.Security.MembershipUser result = null;
            status = System.Web.Security.MembershipCreateStatus.Success;

            using (db = new BuildingEntities())
            {
                count = db.Users.Where(val => val.Login.ToLower() == username.ToLower() && !val.Deleted).Count();

                if (count > 0)
                {
                    status = System.Web.Security.MembershipCreateStatus.DuplicateUserName;
                }
                else
                {
                    user            = new User();
                    user.Login      = username;
                    user.Password   = password.ToSha1Base64String();
                    user.Name       = string.Empty;
                    user.Surname    = string.Empty;
                    user.Patronymic = string.Empty;
                    db.Users.AddObject(user);
                    db.SaveChanges();
                    result = ConvertUser(user);
                }
            }
            return(result);
        }
示例#5
0
        public string GetEmail(BuildingEntities db)
        {
            string result = null;
            var    cp     = db.ContactPersons.Find(val => val.ContractorID == this.ID && val.IsMain).ToList().FirstOrDefault(val => val.EntityState != System.Data.EntityState.Deleted);

            if (cp != null)
            {
                result = string.Join(";", cp.Contacts.Where(val => val.ContactType.SysName.Contains("email") && val.Text.IsNotNullOrEmpty()).Select(val => val.Text));
            }
            if (result.IsNotNullOrEmpty())
            {
                return(result);
            }

            if (TypeID == (int)BuildingEntities.ContractorTypesEnum.Person)
            {
                PhysicalDetail details = this.PhysicalDetails.FirstOrDefault();
                result = details != null ? details.Email : string.Empty;
            }

            if (result.IsNotNullOrEmpty() && Users.Any())
            {
                return(string.Join(";", Users.Select(val => val.Email)));
            }

            return(result);
        }
示例#6
0
        public void OnInserted(EntityJs.Client.Events.EntityEventArgs e)
        {
            BuildingEntities db = (BuildingEntities)e.Context;

            this.CreatorName = db.CurrentUser.FullName;
            SendNotification(db);
        }
示例#7
0
        public void OnCheckPermissions(EntityJs.Client.Events.CheckPermissionsEventArgs e)
        {
            BuildingEntities db   = (BuildingEntities)e.Context;
            User             user = db.CurrentUser;

            e.Cancel = user.RoleID > (int)RolesEnum.Boss;
        }
示例#8
0
文件: Project.cs 项目: diliger/AdCrm
        public void OnCheckPermissions(EntityJs.Client.Events.CheckPermissionsEventArgs e)
        {
            BuildingEntities db   = (BuildingEntities)e.Context;
            User             user = db.CurrentUser;

            //e.Action == EntityJs.Client.Events.ActionsEnum.Delete && !this.ParentID.HasValue ||
            e.Cancel = StatusID == ProjectStatusesEnum.Hidden && user.RoleID != (int)RolesEnum.Admin;
            if (e.Cancel || this.Deleted)
            {
                return;
            }

            if (this.Archived && e.Action == EntityJs.Client.Events.ActionsEnum.Edit)
            {
                List <string> keys = e.Values.Keys.ToList();
                keys.ForEach(val =>
                {
                    if (val != "Archived" && val != "Deleted")
                    {
                        e.Values.Remove(val);
                    }
                });
            }
            if (user.RoleID == (int)RolesEnum.Client)
            {
                e.Cancel = (e.Action == EntityJs.Client.Events.ActionsEnum.Delete && this.CreatorID != user.ID) || this.ContractorID != user.ContractorID;
                //e.Cancel = e.Action != EntityJs.Client.Events.ActionsEnum.Select || this.ContractorID != user.ContractorID;
            }
        }
示例#9
0
文件: Employee.cs 项目: diliger/AdCrm
        public void OnCheckPermissions(EntityJs.Client.Events.CheckPermissionsEventArgs e)
        {
            BuildingEntities db   = (BuildingEntities)e.Context;
            User             user = db.CurrentUser;

            if (user.RoleID <= (int)RolesEnum.Manager)
            {
                e.Cancel = false;
            }
            else if (user.RoleID == (int)RolesEnum.Employee)
            {
                string[] notAllowed = new[] { "DepartmentID", "PositionID", "Archived", "Deleted", "ArchiveDate", "UserID", "WalletID" };
                e.Cancel = user.EmployeeID != this.ID && (e.Action != EntityJs.Client.Events.ActionsEnum.Select || e.EntityMode.StringAndTrim().ToLower() != "autocomplete");
                foreach (string item in notAllowed)
                {
                    e.Values.Remove(item);
                }
            }
            else
            {
                e.Cancel = e.Action != EntityJs.Client.Events.ActionsEnum.Select;
            }
            //int userID = e.Values.ContainsKey("UserID") ? e.Values["UserID"].StringAndTrim().ToInt() : 0;

            //if (!e.Cancel && db.Employees.Any(val => val.UserID == userID && val.ID != this.ID && !val.Deleted))
            //{
            //    e.Cancel = true;
            //    e.Errors.Add("{DuplicateUser:'******'}");
            //}
        }
示例#10
0
文件: Incident.cs 项目: diliger/AdCrm
        public void OnUpdated(EntityJs.Client.Events.EntityEventArgs e)
        {
            BuildingEntities db = (BuildingEntities)e.Context;
            DateTime         date;
            User             user = db.CurrentUser;

            if (RemindDate.HasValue)
            {
                date       = RemindDate.Value.Date;
                RemindDate = RemindTime.IsNotNullOrEmpty() ? date.Add(TimeSpan.Parse(RemindTime)) : date;
            }

            date = DateTime.Now;
            IncidentUser iu = db.IncidentUsers.FirstOrDefault(val => val.IncidentID == this.ID && val.UserID == user.ID);

            if (Read && iu == null)
            {
                iu = new IncidentUser()
                {
                    ChangeDate = date, ChangerID = db.CurrentUser.ID, CreateDate = date, CreatorID = db.CurrentUser.ID, Done = true, Incident = this, UserID = db.CurrentUser.ID
                };
                db.IncidentUsers.AddObject(iu);
            }
            if (iu != null && iu.Done != Read)
            {
                iu.Done       = Read;
                iu.ChangerID  = user.ID;
                iu.ChangeDate = date;
            }
        }
示例#11
0
 public void OnDeleting(EntityJs.Client.Events.EntityEventArgs e)
 {
     try
     {
         BuildingEntities db = (BuildingEntities)e.Context;
         var child           = this.ChildFolders.ToList();
         foreach (var item in child)
         {
             EntityJs.Client.Events.EntityEventArgs args = new EntityJs.Client.Events.EntityEventArgs(db, "Folders", "Folder", item, EntityJs.Client.Events.ActionsEnum.Delete);
             item.OnDeleting(args);
             db.DeleteObject(item);
             item.OnDeleted(args);
         }
         var files = this.Files.ToList();
         foreach (var item in files)
         {
             EntityJs.Client.Events.EntityEventArgs args = new EntityJs.Client.Events.EntityEventArgs(db, "Files", "File", item, EntityJs.Client.Events.ActionsEnum.Delete);
             item.OnDeleting(args);
             db.DeleteObject(item);
             item.OnDeleted(args);
         }
     }
     catch (Exception ex)
     {
         new Log().Error(ex);
     }
 }
示例#12
0
        public void OnCheckPermissions(EntityJs.Client.Events.CheckPermissionsEventArgs e)
        {
            BuildingEntities db   = (BuildingEntities)e.Context;
            User             user = db.CurrentUser;

            e.Cancel = user.RoleID != (int)RolesEnum.Admin && Frozen && (e.Action == EntityJs.Client.Events.ActionsEnum.Edit || e.Action == EntityJs.Client.Events.ActionsEnum.Delete);
        }
示例#13
0
        public void OnInserting(EntityJs.Client.Events.EntityEventArgs e)
        {
            BuildingEntities db   = (BuildingEntities)e.Context;
            User             user = db.CurrentUser;

            this.UserID = user.ID;
        }
示例#14
0
文件: Project.cs 项目: diliger/AdCrm
        public void OnUpdated(EntityJs.Client.Events.EntityEventArgs e)
        {
            BuildingEntities db = (BuildingEntities)e.Context;

            if (this.Deleted)
            {
                List <ProjectTask> tasks    = this.ProjectTasks.ToList();
                List <ProjectNote> notes    = this.ProjectNotes.ToList();
                List <Project>     projects = this.ChildProjects.ToList();

                foreach (ProjectTask task in tasks)
                {
                    EntityJs.Client.Events.EntityEventArgs args = new EntityJs.Client.Events.EntityEventArgs(db, "ProjectTasks", "ProjectTask", task, EntityJs.Client.Events.ActionsEnum.Delete);
                    task.OnDeleting(args);
                    db.DeleteObject(task);
                    task.OnDeleted(args);
                }
                foreach (ProjectNote note in notes)
                {
                    EntityJs.Client.Events.EntityEventArgs args = new EntityJs.Client.Events.EntityEventArgs(db, "ProjectNotes", "ProjectNote", note, EntityJs.Client.Events.ActionsEnum.Delete);
                    note.OnDeleting(args);
                    db.DeleteObject(note);
                    note.OnDeleted(args);
                }
                foreach (Project project in projects)
                {
                    EntityJs.Client.Events.EntityEventArgs args = new EntityJs.Client.Events.EntityEventArgs(db, "Projects", "Project", project, EntityJs.Client.Events.ActionsEnum.Edit);
                    project.OnDeleting(args);
                    project.Deleted = true;
                    project.OnDeleted(args);
                }
            }
        }
示例#15
0
文件: Employee.cs 项目: diliger/AdCrm
        public void OnUpdated(EntityJs.Client.Events.EntityEventArgs e)
        {
            BuildingEntities db    = (BuildingEntities)e.Context;
            List <User>      users = db.Users.Where(val => (this.UserID.HasValue && val.ID == this.UserID) || (val.EmployeeID.HasValue && val.EmployeeID == this.ID)).ToList();

            users.ForEach(val =>
            {
                if (val.ID == this.UserID)
                {
                    val.EmployeeID = this.ID;
                }
                else
                {
                    val.EmployeeID = null;
                }

                if (val.ID == db.CurrentUser.ID)
                {
                    db.CurrentUser = val;
                }
            });

            UpdateSalaryBalance();
            if (this.Deleted && this.Wallet != null)
            {
                this.Wallet.Deleted = true;
            }
        }
示例#16
0
文件: Incident.cs 项目: diliger/AdCrm
        public void OnSelected(EntityJs.Client.Events.EntityEventArgs e)
        {
            BuildingEntities db   = (BuildingEntities )e.Context;
            User             user = db.CurrentUser;

            RemindTime = RemindDate.HasValue ? RemindDate.Value.ToShortTimeString() : "";
            Read       = db.IncidentUsers.Any(val => val.IncidentID == this.ID && val.UserID == user.ID && val.Done);
        }
示例#17
0
文件: Contract.cs 项目: diliger/AdCrm
 public void OnUpdated(EntityJs.Client.Events.EntityEventArgs e)
 {
     if (ParentID.HasValue)
     {
         BuildingEntities db     = (BuildingEntities)e.Context;
         Contract         parent = db.Contracts.FirstOrDefault(val => val.ID == ParentID && val.ContractorID == this.ContractorID);
         ParentID = parent == null ? null : ParentID;
     }
 }
示例#18
0
        public void OnDeleting(EntityJs.Client.Events.EntityEventArgs e)
        {
            BuildingEntities db = (BuildingEntities)e.Context;

            if (this.File != null)
            {
                this.File.RemoveFile();
                db.Files.DeleteObject(this.File);
            }
        }
示例#19
0
文件: Invoice.cs 项目: diliger/AdCrm
        public void OnDeleting(EntityJs.Client.Events.EntityEventArgs e)
        {
            BuildingEntities db       = (BuildingEntities)e.Context;
            List <Payment>   payments = Payments.ToList();

            foreach (Payment p in payments)
            {
                db.DeleteObject(p);
            }
        }
示例#20
0
文件: Project.cs 项目: diliger/AdCrm
        public void OnUpdating(EntityJs.Client.Events.EntityEventArgs e)
        {
            BuildingEntities db = (BuildingEntities)e.Context;

            if (e.Values.ContainsKey("ResponsibleID") && e.Values["ResponsibleID"].StringAndTrim().ToInt() > 0)
            {
                int id = e.Values["ResponsibleID"].StringAndTrim().ToInt();
                //this.ManagerFee = db.Users.FirstOrDefault(val => val.ID == id).ManagerFee;
            }
        }
示例#21
0
 public static void RepeatIncidentsAsync()
 {
     new System.Threading.Thread(new System.Threading.ThreadStart(() =>
     {
         BuildingEntities db = new BuildingEntities();
         db.RepeatIncidents();
         db.SaveChanges();
         db.Dispose();
     })).Start();
 }
示例#22
0
        public void OnInserted(EntityJs.Client.Events.EntityEventArgs e)
        {
            BuildingEntities db = (BuildingEntities)e.Context;

            this.Phone = GetPhone(db);
            this.Email = GetEmail(db);
            if (this.TypeID == 0)
            {
                this.TypeID = ContractorTypesEnum.Company;
            }
        }
示例#23
0
        public void OnCheckPermissions(EntityJs.Client.Events.CheckPermissionsEventArgs e)
        {
            e.Cancel = e.Action == EntityJs.Client.Events.ActionsEnum.Delete || e.Action != EntityJs.Client.Events.ActionsEnum.Select && this.TypeID == WalletTypesEnum.EmployeeWallet;
            BuildingEntities db   = (BuildingEntities)e.Context;
            User             user = db.CurrentUser;

            if (user.RoleID == (int)RolesEnum.Employee)
            {
                e.Cancel = e.Action != EntityJs.Client.Events.ActionsEnum.Select;// || this.EmployeeID != user.EmployeeID && !this.EmployeeWallets.Any(val => val.EmployeeID == user.EmployeeID && val.Available);
            }
        }
示例#24
0
文件: Incident.cs 项目: diliger/AdCrm
        public void OnDeleting(EntityJs.Client.Events.EntityEventArgs e)
        {
            BuildingEntities db = (BuildingEntities)e.Context;

            if (this.PrimaryID.HasValue)
            {
                List <Incident> incs = db.Incidents.Where(val => val.SecondaryID == this.ID).ToList();

                incs.ForEach(val => val.SecondaryID = null);
            }
        }
示例#25
0
        public override bool RoleExists(string roleName)
        {
            BuildingEntities db;
            bool             result;

            using (db = new BuildingEntities())
            {
                result = db.Roles.FirstOrDefault(val => val.SysName == roleName) != null;
            }

            return(result);
        }
示例#26
0
        public override string[] GetAllRoles()
        {
            List <string>    roles;
            BuildingEntities db;

            using (db = new BuildingEntities())
            {
                roles = db.Roles.Select(val => val.SysName).ToList();
            }

            return(roles.ToArray());
        }
示例#27
0
        public override string[] GetUsersInRole(string roleName)
        {
            BuildingEntities db;
            List <string>    users = new List <string>();

            using (db = new BuildingEntities())
            {
                users = db.Roles.FirstOrDefault(val => val.SysName == roleName).Users.Select(val => val.Login).ToList();
            }

            return(users.ToArray());
        }
示例#28
0
文件: Employee.cs 项目: diliger/AdCrm
        public void OnInserted(EntityJs.Client.Events.EntityEventArgs e)
        {
            DateTime         date = DateTime.Now;
            BuildingEntities db   = (BuildingEntities)e.Context;
            int    userID         = db.CurrentUser.ID;
            Wallet wallet         = new Wallet()
            {
                ChangeDate = date, ChangerID = userID, CreateDate = date, CreatorID = userID, EmployeeID = this.ID, Name = this.FullName, TypeID = WalletTypesEnum.EmployeeWallet
            };

            db.Wallets.AddObject(wallet);
        }
示例#29
0
        public void OnDeleting(EntityJs.Client.Events.EntityEventArgs e)
        {
            BuildingEntities db = (BuildingEntities)e.Context;
            var files           = this.Files.ToList();

            foreach (ProjectFile file in files)
            {
                var args = new EntityJs.Client.Events.CheckPermissionsEventArgs(db, "ProjectFiles", "ProjectFile", file, EntityJs.Client.Events.ActionsEnum.Delete);
                file.OnDeleting(args);
                db.ProjectFiles.DeleteObject(file);
                file.OnDeleted(args);
            }
        }
示例#30
0
        public void OnCheckPermissions(EntityJs.Client.Events.CheckPermissionsEventArgs e)
        {
            e.Cancel = false;
            BuildingEntities db   = (BuildingEntities)e.Context;
            User             user = db.CurrentUser;
            Employee         emp  = db.CurrentEmployee;

            e.Cancel = user.RoleID != (int)RolesEnum.Admin && Frozen && (e.Action == EntityJs.Client.Events.ActionsEnum.Edit || e.Action == EntityJs.Client.Events.ActionsEnum.Delete);

            if (!e.Cancel && user.RoleID == (int)RolesEnum.Employee)
            {
                e.Cancel = this.WalletFromID != emp.WalletID && this.WalletToID != emp.WalletID || this.WalletFromID != emp.WalletID && e.Action != EntityJs.Client.Events.ActionsEnum.Select;
            }
        }