/// <summary>
        /// 将新增的业务模型对象保存到数据库表,并返回新增后的Id
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        public virtual int Add(TModel t)
        {
            TEntity data = _dataMapper.ToEntity(t);

            _innerDataProvider.BeginTrans();
            ProcessCollections(t, data);
            try
            {
                var r = _innerDataProvider.Add(data);
                ProcessAttachmentCollections(t, data);
                _dataMapper.SaveLanguages(_innerDataProvider, data, t);
                _innerDataProvider.EndTrans();
                t.Id = data.Id;
                return(data.Id);
            }
            catch (System.Data.Entity.Validation.DbEntityValidationException ex)
            {
                var errMsg = "Validation Error:" + String.Join(";", ex.EntityValidationErrors.Select(val => String.Join(",", val.ValidationErrors.Select(v => v.ErrorMessage))));
                _innerDataProvider.RollbackTrans();
                throw new JException(errMsg);
            }
            catch
            {
                _innerDataProvider.RollbackTrans();
                throw;
            }
        }
Exemple #2
0
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="authTokenModel">数据节点对象</param>
        /// <returns></returns>
        public bool Delete(DepartmentModel organizationModel)
        {
            var _context = SiteManager.Kernel.Get <ModelContext>();
            EFAuditDataService <DepartmentModel> efMain = new EFAuditDataService <DepartmentModel>(_context);
            EFAuditDataService <DepPostModel>    efPost = new EFAuditDataService <DepPostModel>(_context);
            EFAuditDataService <DepUserModel>    efUser = new EFAuditDataService <DepUserModel>(_context);

            try
            {
                int row = 0;
                #region 组织机构与岗位信息
                List <DepPostModel> postList = efPost.GetQuery().Where(p => p.DepId == organizationModel.Id).ToList();
                foreach (DepPostModel item in postList)
                {
                    row = efPost.Delete(item);
                    if (row < 0)
                    {
                        efMain.RollbackTrans();
                        return(false);
                    }
                }
                #endregion

                #region 组织机构与用户信息
                List <DepUserModel> userList = efUser.GetQuery().Where(p => p.DepId == organizationModel.Id).ToList();
                foreach (DepUserModel item in userList)
                {
                    row = efUser.Delete(item);
                    if (row < 0)
                    {
                        efMain.RollbackTrans();
                        return(false);
                    }
                }
                #endregion

                #region 组织机构主表数据
                row = efMain.Delete(organizationModel);
                if (row < 0)
                {
                    efMain.RollbackTrans();
                    return(false);
                }
                #endregion
            }
            catch (Exception)
            {
                efMain.RollbackTrans();
                throw;
            }

            efMain.EndTrans();
            return(true);
        }
Exemple #3
0
        /// <summary>
        /// 保存岗位数据
        /// </summary>
        /// <param name="postModelList"></param>
        /// <returns></returns>
        public bool SavePostInfo(List <PostModel> postModelList)
        {
            var _context = SiteManager.Kernel.Get <ModelContext>();
            EFAuditDataService <PostModel> efMain = new EFAuditDataService <PostModel>(_context);

            try
            {
                int row = 0;
                #region 岗位信息
                foreach (PostModel item in postModelList)
                {
                    if (item._State.ToUpper() == "ADDED")
                    {
                        row = efMain.Add(item);
                    }
                    else if (item._State.ToUpper() == "MODIFIED")
                    {
                        row = efMain.Change(item);
                    }
                    else if (item._State.ToUpper() == "REMOVED")
                    {
                        row = efMain.Delete(item);
                    }

                    if (row < 0)
                    {
                        efMain.RollbackTrans();
                        return(false);
                    }
                }
                #endregion
            }
            catch (Exception)
            {
                efMain.RollbackTrans();
                throw;
            }

            efMain.EndTrans();
            return(true);
        }
Exemple #4
0
        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="authTokenModel">数据节点对象</param>
        /// <returns></returns>
        public bool SaveInfo(DepartmentModel organizationModel)
        {
            var _context = SiteManager.Kernel.Get <ModelContext>();

            EFAuditDataService <DepartmentModel> efMain = new EFAuditDataService <DepartmentModel>(_context);
            EFAuditDataService <DepPostModel>    efPost = new EFAuditDataService <DepPostModel>(_context);
            EFAuditDataService <DepUserModel>    efUser = new EFAuditDataService <DepUserModel>(_context);

            try
            {
                #region 组织机构主表数据
                efMain.BeginTrans();
                int row = 0;
                if (organizationModel.Id == null || organizationModel.Id <= 0)
                {
                    row = efMain.Add(organizationModel);
                }
                else
                {
                    row = efMain.Change(organizationModel);
                }

                if (row < 0)
                {
                    efMain.RollbackTrans();
                    return(false);
                }
                #endregion

                #region 组织机构与岗位信息
                foreach (DepPostModel item in organizationModel.DepPostModelList)
                {
                    item.DepId          = organizationModel.Id;
                    item.IsActive       = 1;
                    item.ExamineType    = "";
                    item.IsDeleted      = 0;
                    item.IsDisabled     = 0;
                    item.Name           = "";
                    item.CreateDatetime = DateTime.Now;

                    if (item._State.ToUpper() == "ADDED")
                    {
                        row = efPost.Add(item);
                    }
                    else if (item._State.ToUpper() == "MODIFIED")
                    {
                        row = efPost.Change(item);
                    }
                    else if (item._State.ToUpper() == "REMOVED")
                    {
                        row = efPost.Delete(item);
                    }

                    if (row < 0)
                    {
                        efMain.RollbackTrans();
                        return(false);
                    }
                }
                #endregion

                #region 组织机构与用户信息

                foreach (DepUserModel item in organizationModel.DepUserModelList)
                {
                    #region 设置用户的主部门,清除已存在其他主部门标识,确定一个用户只有一个主要部门
                    //如果某个用户设置了主部门首先查询是否在其他部门下已经存在设置,如果存在清除掉,重新写入主部门标识
                    if (item.IsMain == 1)
                    {
                        List <DepUserModel> dList = efUser.GetQuery().Where(u => u.UserName == item.UserName && u.DepId != item.DepId).ToList();
                        foreach (DepUserModel m in dList)
                        {
                            m.IsMain = 0;
                            row      = efUser.Change(m);
                            if (row < 0)
                            {
                                efMain.RollbackTrans();
                                return(false);
                            }
                        }
                    }
                    #endregion

                    item.DepId          = organizationModel.Id;
                    item.ContractLenght = item.ContractLenght == null ? 0 : item.ContractLenght;
                    item.ExamineType    = "";
                    item.IsDeleted      = 0;
                    item.JoinDateTime   = item.JoinDateTime == null ? DateTime.Now : item.JoinDateTime;
                    item.IsSuspension   = item.IsSuspension == null ? 0 : item.ContractLenght;
                    item.IsLeader       = item.IsLeader == null ? 0 : item.IsLeader;
                    item.IsMain         = item.IsMain == null ? 0 : item.IsMain;

                    item.CreateDatetime = DateTime.Now;

                    if (item._State.ToUpper() == "ADDED")
                    {
                        row = efUser.Add(item);
                    }
                    else if (item._State.ToUpper() == "MODIFIED")
                    {
                        row = efUser.Change(item);
                    }
                    else if (item._State.ToUpper() == "REMOVED")
                    {
                        row = efUser.Delete(item);
                    }

                    if (row < 0)
                    {
                        efMain.RollbackTrans();
                        return(false);
                    }
                }


                #endregion
            }
            catch (Exception)
            {
                efMain.RollbackTrans();
                throw;
            }

            efMain.EndTrans();
            return(true);
        }