Пример #1
0
        ///// <summary>首次连接数据库时初始化数据,仅用于实体类重载,用户不应该调用该方法</summary>
        //[EditorBrowsable(EditorBrowsableState.Never)]
        //protected override void InitData()
        //{
        //    base.InitData();

        //    // InitData一般用于当数据表没有数据时添加一些默认数据,该实体类的任何第一次数据库操作都会触发该方法,默认异步调用
        //    // Meta.Count是快速取得表记录数
        //    if (Meta.Count > 0) return;

        //    // 需要注意的是,如果该方法调用了其它实体类的首次数据库操作,目标实体类的数据初始化将会在同一个线程完成
        //    if (XTrace.Debug) XTrace.WriteLine("开始初始化{0}[{1}]数据……", typeof(Facility).Name, Meta.Table.DataTable.DisplayName);

        //    var entity = new Facility();
        //    entity.Serialnum = "abc";
        //    entity.CreateTime = DateTime.Now;
        //    entity.CreateSysUserSerialnum = "abc";
        //    entity.UpdateTime = DateTime.Now;
        //    entity.UpdateSysUserSerialnum = "abc";
        //    entity.Name = "abc";
        //    entity.FarmSerialnum = "abc";
        //    entity.FacilityTypeSerialnum = "abc";
        //    entity.Address = "abc";
        //    entity.PhotoUrl = "abc";
        //    entity.ContactMan = "abc";
        //    entity.ContactPhone = "abc";
        //    entity.ContactMobile = "abc";
        //    entity.Status = 0;
        //    entity.Introduce = "abc";
        //    entity.Sort = 0;
        //    entity.Remark = "abc";
        //    entity.Insert();

        //    if (XTrace.Debug) XTrace.WriteLine("完成初始化{0}[{1}]数据!", typeof(Facility).Name, Meta.Table.DataTable.DisplayName);
        //}

        /// <summary>已重载。删除关联数据</summary>
        /// <returns></returns>
        protected override int OnDelete()
        {
            if (CompanyUsers != null)
            {
                CompanyUsers.Delete();
            }
            if (Devices != null)
            {
                Devices.Delete();
            }
            if (FacilityCameras != null)
            {
                FacilityCameras.Delete();
            }
            if (FacilityCameraRunStatisticss != null)
            {
                FacilityCameraRunStatisticss.Delete();
            }
            if (FacilityProduceInfos != null)
            {
                FacilityProduceInfos.Delete();
            }

            return(base.OnDelete());
        }
Пример #2
0
        public IActionResult UpdateUser()
        {
            CompanyUsers cu = new CompanyUsers();

            cu.Users   = context.Users.ToList();
            cu.Company = context.Companies.ToList();
            return(View(cu));
        }
Пример #3
0
        ///// <summary>首次连接数据库时初始化数据,仅用于实体类重载,用户不应该调用该方法</summary>
        //[EditorBrowsable(EditorBrowsableState.Never)]
        //protected override void InitData()
        //{
        //    base.InitData();

        //    // InitData一般用于当数据表没有数据时添加一些默认数据,该实体类的任何第一次数据库操作都会触发该方法,默认异步调用
        //    // Meta.Count是快速取得表记录数
        //    if (Meta.Count > 0) return;

        //    // 需要注意的是,如果该方法调用了其它实体类的首次数据库操作,目标实体类的数据初始化将会在同一个线程完成
        //    if (XTrace.Debug) XTrace.WriteLine("开始初始化{0}[{1}]数据……", typeof(SysUser).Name, Meta.Table.DataTable.DisplayName);

        //    var entity = new SysUser();
        //    entity.Serialnum = "abc";
        //    entity.CreateTime = DateTime.Now;
        //    entity.CreateSysUserSerialnum = "abc";
        //    entity.UpdateTime = DateTime.Now;
        //    entity.UpdateSysUserSerialnum = "abc";
        //    entity.LoginName = "abc";
        //    entity.UserName = "******";
        //    entity.Email = "abc";
        //    entity.QQ = "abc";
        //    entity.Password = "******";
        //    entity.Status = 0;
        //    entity.LastIP = "abc";
        //    entity.LastTime = DateTime.Now;
        //    entity.LastUrl = "abc";
        //    entity.SysRoleSerialnum = "abc";
        //    entity.SysDepartmentSerialnum = "abc";
        //    entity.Sort = 0;
        //    entity.Remark = "abc";
        //    entity.Insert();

        //    if (XTrace.Debug) XTrace.WriteLine("完成初始化{0}[{1}]数据!", typeof(SysUser).Name, Meta.Table.DataTable.DisplayName);
        //}

        /// <summary>已重载。删除关联数据</summary>
        /// <returns></returns>
        protected override int OnDelete()
        {
            if (CompanyUsers != null)
            {
                CompanyUsers.Delete();
            }

            return(base.OnDelete());
        }
Пример #4
0
        public int CreateCompany(string value, Guid createdBy)
        {
            var company = new Database.Entities.Company {
                Name = value, CreatedBy = createdBy, CreatedOn = DateTime.Now
            };
            var companyUser = new CompanyUsers()
            {
                Company = company, UserId = createdBy
            };

            _dbContext.CompanyUsers.Add(companyUser);
            _dbContext.SaveChanges();

            return(companyUser.CompanyId);
        }
Пример #5
0
        public IActionResult UpdateUser(int uid, string userName, string userPassword)
        {
            User user = context.Users.FirstOrDefault(i => i.UserId == uid);

            user.UserName = userName;
            user.password = userPassword;
            ////admin yapma
            //user.UserRole = false;

            context.SaveChanges();

            CompanyUsers cu = new CompanyUsers();

            cu.Users   = context.Users.ToList();
            cu.Company = context.Companies.ToList();
            return(View(cu));
        }
Пример #6
0
        /// <summary>
        /// 注册用户
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public Boolean RegisterUser(UserDto dto)
        {
            Boolean result = false;
            var     entity = _mapper.Map <Users>(dto);

            // 新建单位
            var companyid = FreeSqlFactory._Freesql.Insert <Company>(new Company()
            {
                CompanyName  = dto.Phone,
                CompanyPhone = dto.Phone,
                CompanyLegal = dto.Name,
                GrantMode    = GrantMode.CompanyGrant
            }).ExecuteIdentity();

            entity.CompanyId = companyid;

            var userid = FreeSqlFactory._Freesql.Insert <Users>(entity).ExecuteIdentity();

            entity = FreeSqlFactory._Freesql.Select <Users>().Where(x => x.Id == userid).ToList().First();

            entity.Password = (entity.Password + userid.ToStringExtension()).ToMD5();
            FreeSqlFactory._Freesql.Update <Users>().SetSource(entity).ExecuteAffrows();

            // 加入单位用户
            CompanyUsers companyUsers = new CompanyUsers()
            {
                UserId    = userid,
                JobStatus = JobStatus.InJob,
                CompanyId = companyid
            };

            FreeSqlFactory._Freesql.Insert <CompanyUsers>(companyUsers).ExecuteAffrows();

            dto.Id = userid;
            return(result);
        }
Пример #7
0
        public Users DefaultValues(UserSimple User)
        {
            var password        = User.password;
            var password_origem = User.password;

            using (MD5 md5Hash = MD5.Create())
            {
                password = Token.GetMd5Hash(md5Hash, User.password);
            }
            Companies _companie = new Companies();
            Users     _user     = new Users();

            //Default data User
            _user.full_name          = User.full_name;
            _user.email              = User.email;
            _user.password           = password;
            _user.createdat          = DateTime.Now;
            _user.last_acess         = DateTime.Now;
            _user.type_user          = 1;
            _user.fk_company_default = _companie.id_company;
            _user.phone              = User.phone;
            _csxContext.Users.Add(_user);

            //Default data Company
            _companie.full_name      = User.company_name;
            _companie.createdat      = DateTime.Now;
            _companie.fk_user_create = _user.id_user;
            _companie.days_contract  = 30;
            _companie.plan           = "FREE";
            _csxContext.Companies.Add(_companie);

            CompanyUsers _companieUser = new CompanyUsers();

            _companieUser.fk_user        = _user.id_user;
            _companieUser.fk_user_create = _user.id_user;
            _companieUser.fk_company     = _companie.id_company;
            _companieUser.createdat      = DateTime.Now;
            _companieUser.updatedat      = DateTime.Now;
            _companieUser.fk_role        = 1;
            _csxContext.CompanyUsers.Add(_companieUser);

            Surveys _survey = new Surveys();

            _survey.title          = DefaultSurveyTitle(User.language);
            _survey.description    = DefaultSurveyDescription(User.language);
            _survey.active         = true;
            _survey.fk_company     = _companie.id_company;
            _survey.createdat      = DateTime.Now;
            _survey.updatedat      = DateTime.Now;
            _survey.fk_user_create = _user.id_user;
            _survey.language       = DefaultLanguage(User.language);
            _csxContext.Surveys.Add(_survey);

            _csxContext.SaveChanges();

            //Update CompanyId on User
            var newUser = _csxContext.Users.Find(_user.id_user);

            newUser.fk_company_default = _companie.id_company;
            _csxContext.Users.Update(newUser);

            //Generate MD5 URL Survey
            var newSurvey = _csxContext.Surveys.Find(_survey.id_survey);

            _csxContext.Surveys.Update(newSurvey);
            _csxContext.SaveChanges();

            //TODO: Configurar email e tirar comentário
            //SendEmail.WelcomeUser(_user, _companie, password_origem);
            return(_user);
        }
Пример #8
0
        public ResponseDto <Users> Save([FromBody] Users request)
        {
            ResponseDto <Users> response = new ResponseDto <Users>();

            var _entity = _appSystemServices.GetEntitys <Users>();

            request.CompanyId = CurrentUser.CompanyId;
            if (string.IsNullOrEmpty(request.Id.ToStringExtension()) || request.Id.ToInt32() == 0)
            {
                var userId = _appSystemServices.Create <Users>(request);

                if (string.IsNullOrEmpty(request.Password))
                {
                    request.Id       = userId;
                    request.Password = ("123456".ToMD5() + userId.ToStringExtension()).ToMD5();
                    request.SetModifyDefault(this.CurrentUser);
                    _appSystemServices.Modify <Users>(request);
                }


                // 加入单位用户
                // 加入单位用户
                CompanyUsers companyUsers = new CompanyUsers()
                {
                    UserId    = userId,
                    JobStatus = JobStatus.Audit,
                    CompanyId = CurrentUser.CompanyId
                };
                companyUsers.SetCreateDefault(this.CurrentUser);
                _appSystemServices.Create <CompanyUsers>(companyUsers);

                if (!request.DepartmentId.IsNull() && request.DepartmentId.Count > 0)
                {
                    List <DepartmentUsers> departmentUsers = new List <DepartmentUsers>();
                    request.DepartmentId.ForEach(p => {
                        var departuser = new DepartmentUsers()
                        {
                            CompanyId = CurrentUser.CompanyId, DepartmentId = p, UserId = userId
                        };
                        departuser.SetCreateDefault(this.CurrentUser);
                        departmentUsers.Add(departuser);
                    });
                    _appSystemServices.Create <DepartmentUsers>(departmentUsers.ToArray());
                }
                if (!request.RoleId.IsNull() && request.RoleId.Count > 0)
                {
                    List <RoleUsers> roleUsers = new List <RoleUsers>();
                    request.RoleId.ForEach(p =>
                    {
                        var roleuser = new RoleUsers()
                        {
                            CompanyId = CurrentUser.CompanyId, RoleId = p, UserId = userId
                        };
                        roleuser.SetCreateDefault(this.CurrentUser);
                        roleUsers.Add(roleuser);
                        _appSystemServices.Create <RoleUsers>(roleUsers.ToArray());
                    });
                }
            }
            else
            {
                _appSystemServices.Modify <Users>(request);

                if (!request.DepartmentId.IsNull())
                {
                    _appSystemServices.GetEntitys <DepartmentUsers>().Where(x => x.UserId == request.Id && x.CompanyId == CurrentUser.CompanyId).ToDelete().ExecuteAffrows();
                    _appSystemServices.GetEntitys <RoleUsers>().Where(x => x.UserId == request.Id && x.CompanyId == CurrentUser.CompanyId).ToDelete().ExecuteAffrows();

                    if (!request.DepartmentId.IsNull() && request.DepartmentId.Count > 0)
                    {
                        List <DepartmentUsers> departmentUsers = new List <DepartmentUsers>();
                        request.DepartmentId.ForEach(p => {
                            var departuser = new DepartmentUsers()
                            {
                                CompanyId = CurrentUser.CompanyId, DepartmentId = p, UserId = request.Id
                            };
                            departuser.SetCreateDefault(this.CurrentUser);
                            departmentUsers.Add(departuser);
                        });
                        _appSystemServices.Create <DepartmentUsers>(departmentUsers.ToArray());
                    }

                    if (!request.RoleId.IsNull() && request.RoleId.Count > 0)
                    {
                        List <RoleUsers> roleUsers = new List <RoleUsers>();
                        request.RoleId.ForEach(p =>
                        {
                            var roleuser = new RoleUsers()
                            {
                                CompanyId = CurrentUser.CompanyId, RoleId = p, UserId = request.Id
                            };
                            roleuser.SetCreateDefault(this.CurrentUser);
                            roleUsers.Add(roleuser);
                            _appSystemServices.Create <RoleUsers>(roleUsers.ToArray());
                        });
                    }
                }
            }
            return(response);
        }