Esempio n. 1
0
        public BaseResponse <SystemConfig> AddSystemConfig(SystemConfig model)
        {
            var response = new BaseResponse <SystemConfig>();
            var errors   = Validate <SystemConfig>(model, new SystemConfigValidator());

            if (errors.Count() > 0)
            {
                BaseResponse <SystemConfig> errResponse = new BaseResponse <SystemConfig>(model, errors);
                errResponse.IsSuccess = false;
                return(errResponse);
            }
            try
            {
                model.CreatedOn = DateTime.Now;
                response.Value  = _systemConfigRepository.Add(model);
                try
                {
                    _applicationLoggingRepository.Log("EVENT", "CREATE", "SystemConfig", response.Value.Id.ToString(), "", "", model, "", System.Web.HttpContext.Current.Request.UserHostAddress, model.CreatedBy);
                }
                catch
                { }
                if (model.IsSystemConfig == false)
                {
                    DepartmentQuery query = new DepartmentQuery();
                    query.Keyword  = "";
                    query.ParentId = 0;
                    query.Active   = true;
                    List <SPGetDepartment_Result> arrDepartments = _departmentRepository.Filter(query).Where(n => n.ParentId != 0).ToList();
                    SystemConfigDepartment        config;
                    if (arrDepartments.Count() > 0)
                    {
                        foreach (var item in arrDepartments)
                        {
                            config              = new SystemConfigDepartment();
                            config.ConfigId     = response.Value.Id;
                            config.Value        = model.Value;
                            config.Description  = model.Description;
                            config.DepartmentId = item.Id;
                            config.CreatedBy    = model.CreatedBy;
                            config.CreatedOn    = model.CreatedOn;
                            config.EditedBy     = model.EditedBy;
                            config.EditedOn     = model.EditedOn;
                            _systemConfigDepartmentRepository.Add(config);
                            try
                            {
                                _applicationLoggingRepository.Log("EVENT", "CREATE", "SystemConfigDepartment", response.Value.Id.ToString(), "", "", config, "", System.Web.HttpContext.Current.Request.UserHostAddress, model.CreatedBy);
                            }
                            catch
                            { }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                response.IsSuccess = false;
                response.Message   = "Error: " + ex.Message + " StackTrace: " + ex.StackTrace;
            }
            return(response);
        }
        public List <SPBuildOrganizationTree_Result> BuildOrganizationTree(DepartmentQuery query)
        {
            List <SPBuildOrganizationTree_Result> result = new List <SPBuildOrganizationTree_Result>();

            result = _entities.SPBuildOrganizationTree(query.DepartmentId, query.Type, query.Action).ToList();
            return(result);
        }
Esempio n. 3
0
        private void Department_Load(object sender, EventArgs e)
        {
            if (!IsEdit)
            {
                var departmentId = Guid.NewGuid().ToString();

                while (new DepartmentQuery().GetDepartment(departmentId) != null)
                {
                    departmentId = Guid.NewGuid().ToString();
                }

                Txt_DepartmentID.Text = departmentId;
            }
            else
            {
                var items = new DepartmentQuery().GetDepartment(DepartmentID);
                if (items != null)
                {
                    Txt_DepartmentID.Text   = items.ObjectID;
                    Txt_DepartmentName.Text = items.DepartmentName;
                    if (items.IsEnable == "Y")
                    {
                        Rbtn_Yes.Checked = true;
                    }
                    else
                    {
                        Rbtn_No.Checked = true;
                    }
                }
            }
        }
        public List <SPGetDepartment_Result> Filter(DepartmentQuery query)
        {
            var keyword = string.IsNullOrEmpty(query.Keyword) != true ? query.Keyword : "";
            List <SPGetDepartment_Result> result = new List <SPGetDepartment_Result>();

            result = _entities.SPGetDepartment(Util.DetecVowel(keyword), query.ParentId, query.Active).ToList();
            return(result);
        }
        public List <SelectView> Sub(string id)
        {
            DepartmentQuery query = new DepartmentQuery()
            {
                ParentId = id
            };

            return(_Service.Select(query));
        }
        public BaseListResponse <SPGetDepartment_Result> GetSubDepartmentNonSeft(DepartmentQuery query)
        {
            var response = new BaseListResponse <SPGetDepartment_Result>();

            try
            {
                response.Data = _departmentRepository.Filter(query).Where(n => n.Id != query.ParentId).OrderBy(n => n.Order).ToList();
            }
            catch (Exception ex)
            {
                response.Message = "Error: " + ex.Message + " StackTrace: " + ex.StackTrace;
            }
            return(response);
        }
        public BaseListResponse <SPGetDepartment_Result> FilterDepartment(DepartmentQuery query)
        {
            var response = new BaseListResponse <SPGetDepartment_Result>();

            try
            {
                response.Data = _departmentRepository.Filter(query);
            }
            catch (Exception ex)
            {
                response.Message = "Error: " + ex.Message + " StackTrace: " + ex.StackTrace;
            }
            return(response);
        }
Esempio n. 8
0
        public ActionResult GetDepartmentAuditorList()
        {
            try
            {
                var queryParams = new NameValueCollection();
                if (!ParamHelper.CheckParaQ(ref queryParams))
                {
                    return(Json(new ResponseEntity <int>(RegularFunction.RegularSqlRegexText), JsonRequestBehavior.AllowGet));
                }

                var query = new DepartmentQuery(queryParams);

                var sqlCondition = new StringBuilder();
                sqlCondition.Append("ISNULL(IsDelete,0)!=1");

                if (!string.IsNullOrEmpty(query.Name))
                {
                    sqlCondition.Append($" and Name like '%{query.Name}%'");
                }

                PageRequest preq = new PageRequest
                {
                    TableName      = " [Department] ",
                    Where          = sqlCondition.ToString(),
                    Order          = " Id DESC ",
                    IsSelect       = true,
                    IsReturnRecord = true,
                    PageSize       = query.PageSize,
                    PageIndex      = query.PageIndex,
                    FieldStr       = "*"
                };

                var result = new DepartmentBLL().GetView_DepartmentAuditorByPage(preq);

                var response = new ResponseEntity <object>(true, string.Empty,
                                                           new DataGridResultEntity <View_DepartmentAuditor>
                {
                    TotalRecords   = preq.Out_AllRecordCount,
                    DisplayRecords = preq.Out_PageCount,
                    ResultData     = result
                });

                return(Json(response, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(Json(new ResponseEntity <object>(-999, string.Empty, ""), JsonRequestBehavior.AllowGet));
            }
        }
        public List <SelectView> MySub()
        {
            if (string.IsNullOrWhiteSpace(LogonInfo.DepartmentId))
            {
                ApiException.ThrowBadRequest("您需要先有所属部门才可执行此操作");
            }

            DepartmentQuery query = new DepartmentQuery()
            {
                ParentId = LogonInfo.DepartmentId
            };
            List <SelectView> subList = _Service.Select(query);

            return(subList);
        }
        public static DepartmentFilter CreateFromDepartmentQuery(DepartmentQuery query, DepartmentFilter existedFilter = null)
        {
            var filter = existedFilter ?? new DepartmentFilter();

            switch (query.Field)
            {
            case DepartmentQueryFields.Code:
                filter.Code = query.Value;
                break;

            case DepartmentQueryFields.Name:
                filter.Name = query.Value;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            return(filter);
        }
Esempio n. 11
0
        private void User_Load(object sender, EventArgs e)
        {
            var unitItem = new DepartmentQuery().GetDepartments();

            //Com_DepartmentID.Items.Clear();
            Com_DepartmentID.DataSource    = unitItem;
            Com_DepartmentID.ValueMember   = "ObjectID";
            Com_DepartmentID.DisplayMember = "DepartmentName";

            if (!IsEdit)
            {
                var userId = Guid.NewGuid().ToString();

                while (new DepartmentQuery().GetDepartment(userId) != null)
                {
                    userId = Guid.NewGuid().ToString();
                }

                Txt_UserID.Text = userId;
            }
            else
            {
                var items = new UserQuery().GetUser(UserID);
                if (items != null)
                {
                    Txt_UserID.Text   = items.ObjectID;
                    Txt_UserName.Text = items.UserName;
                    Com_DepartmentID.SelectedValue = items.UserDepartmentID;

                    if (items.IsEnable == "Y")
                    {
                        Rbtn_Yes.Checked = true;
                    }
                    else
                    {
                        Rbtn_No.Checked = true;
                    }
                }
            }
        }
Esempio n. 12
0
        /// <summary>
        /// Test Find using the Query class
        /// </summary>
        private void Step_30_TestFindByQuery_Generated()
        {
            using (TransactionManager tm = CreateTransaction())
            {
                //Insert Mock Instance
                Department mock   = CreateMockInstance(tm);
                bool       result = DataRepository.DepartmentProvider.Insert(tm, mock);

                Assert.IsTrue(result, "Could Not Test FindByQuery, Insert Failed");

                DepartmentQuery query = new DepartmentQuery();

                query.AppendEquals(DepartmentColumn.DepartmentId, mock.DepartmentId.ToString());
                query.AppendEquals(DepartmentColumn.Name, mock.Name.ToString());
                query.AppendEquals(DepartmentColumn.GroupName, mock.GroupName.ToString());
                query.AppendEquals(DepartmentColumn.ModifiedDate, mock.ModifiedDate.ToString());

                TList <Department> results = DataRepository.DepartmentProvider.Find(tm, query);

                Assert.IsTrue(results.Count == 1, "Find is not working correctly.  Failed to find the mock instance");
            }
        }
        public BaseResponse DeleteLogicalDepartment(int id)
        {
            BaseResponse response = new BaseResponse();
            Department   model    = _departmentRepository.GetById(id);

            try
            {
                DepartmentQuery query = new DepartmentQuery();
                query.Keyword  = "";
                query.Active   = null;
                query.ParentId = id;

                BaseListResponse <SPGetDepartment_Result> lstChild = GetSubDepartmentNonSeft(query);
                var lstStaffs = _staffRepository.SearchStaffs(id, 1, "", null);
                if (lstChild.Data.Count() > 0)
                {
                    response.IsSuccess = false;
                    response.Message   = "Tồn tại đơn vị con. Xóa không thành công";
                }
                else if (lstStaffs.Count() > 0)
                {
                    response.IsSuccess = false;
                    response.Message   = "Tồn tại cán bộ thuộc đơn vị. Xóa không thành công";
                }
                else
                {
                    model.EditedOn = DateTime.Now;
                    model.Deleted  = true;
                    _departmentRepository.Edit(model);
                    _applicationLoggingRepository.Log("EVENT", "DELETE", "Department", model.Id.ToString(), "", "", model, "", HttpContext.Current.Request.UserHostAddress, model.CreatedBy);
                }
            }
            catch (Exception ex)
            {
                response.Message   = ex.Message;
                response.IsSuccess = false;
            }
            return(response);
        }
Esempio n. 14
0
        public BaseResponse <SystemConfig> UpdateSystemConfig(SystemConfig model)
        {
            BaseResponse <SystemConfig> response = new BaseResponse <SystemConfig>();
            var errors = Validate <SystemConfig>(model, new SystemConfigValidator());

            if (errors.Count() > 0)
            {
                BaseResponse <SystemConfig> errResponse = new BaseResponse <SystemConfig>(model, errors);
                errResponse.IsSuccess = false;
                return(errResponse);
            }
            try
            {
                var config = _systemConfigRepository.GetById(model.Id);
                if (config.Title != model.Title)
                {
                    IEnumerable <SystemConfig> listSystemConfig = _systemConfigRepository.FindBy(x => x.Value.ToLower() == model.Value.ToLower() && x.Deleted == false);
                    if (listSystemConfig.Count() > 0)
                    {
                        response.IsSuccess = false;
                        response.Message   = "Cấu hình hệ thống đã tồn tại.";
                    }
                    else
                    {
                        model.EditedOn = DateTime.Now;
                        response.Value = _systemConfigRepository.Update(config, model);
                    }
                }
                else
                {
                    model.EditedOn = DateTime.Now;
                    response.Value = _systemConfigRepository.Update(config, model);
                    try
                    {
                        _applicationLoggingRepository.Log("EVENT", "UPDATE", "SystemConfig", model.Id.ToString(), "", "", model, "", System.Web.HttpContext.Current.Request.UserHostAddress, model.CreatedBy);
                    }
                    catch
                    { }
                }
                //nếu biến cấu hình cũ là có isSystemConfig=false bây giờ =true thì phải thêm các tham số HT đơn vị.
                if (config.IsSystemConfig == false && model.IsSystemConfig == true)
                {
                    IEnumerable <SystemConfigDepartment> lstConfigDepartment = _systemConfigDepartmentRepository.FindBy(n => n.ConfigId == model.Id);
                    if (lstConfigDepartment.Count() > 0)
                    {
                        _systemConfigDepartmentRepository.DeleteMulti(x => x.ConfigId == model.Id);
                    }
                }
                else if (config.IsSystemConfig == true && model.IsSystemConfig == false)
                {
                    DepartmentQuery query = new DepartmentQuery();
                    query.Keyword  = "";
                    query.ParentId = 0;
                    query.Active   = true;
                    List <SPGetDepartment_Result> arrDepartments = _departmentRepository.Filter(query).Where(n => n.ParentId != 0).ToList();
                    SystemConfigDepartment        configSub;
                    if (arrDepartments.Count() > 0)
                    {
                        foreach (var item in arrDepartments)
                        {
                            configSub              = new SystemConfigDepartment();
                            configSub.ConfigId     = response.Value.Id;
                            configSub.Value        = model.Value;
                            configSub.Description  = model.Description;
                            configSub.DepartmentId = item.Id;
                            configSub.CreatedBy    = model.CreatedBy;
                            configSub.CreatedOn    = model.CreatedOn;
                            configSub.EditedBy     = model.EditedBy;
                            configSub.EditedOn     = model.EditedOn;
                            _systemConfigDepartmentRepository.Add(configSub);
                            try
                            {
                                _applicationLoggingRepository.Log("EVENT", "CREATE", "SystemConfigDepartment", response.Value.Id.ToString(), "", "", configSub, "", System.Web.HttpContext.Current.Request.UserHostAddress, model.CreatedBy);
                            }
                            catch
                            { }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                response.IsSuccess = false;
                response.Message   = "Error: " + ex.Message + " StackTrace: " + ex.StackTrace;
            }
            return(response);
        }
 public BaseListResponse <SPBuildOrganizationTree_Result> BuildOrganizationTree([FromUri] DepartmentQuery query)
 {
     return(organizationService.BuildOrganizationTree(query));
 }
 public BaseListResponse <SPGetDepartment_Result> Search([FromUri] DepartmentQuery query)
 {
     return(organizationService.FilterDepartment(query));
 }
 public BaseListResponse <SPGetDepartment_Result> GetSubDepartmentNonSeft([FromUri] DepartmentQuery query)
 {
     return(organizationService.GetSubDepartmentNonSeft(query));
 }
        public BaseListResponse <SPBuildOrganizationTree_Result> BuildOrganizationTree(DepartmentQuery query)
        {
            var response = new BaseListResponse <SPBuildOrganizationTree_Result>();

            try
            {
                response.Data = _departmentRepository.BuildOrganizationTree(query);
            }
            catch (Exception ex)
            {
                response.Message = "Error: " + ex.Message + " StackTrace: " + ex.StackTrace;
            }
            return(response);
        }
Esempio n. 19
0
        public async Task <QueryResult <DepartmentViewModel> > GetDepartmentList(DepartmentQuery queryObj)
        {
            var result = new QueryResult <DepartmentViewModel>();
            var user   = await _userRepo.GetUser(_userRepo.GetLoggedInUserId());

            var query = (from d in _context.OrganizationDepartments
                         //join og in _context.Organizations
                         //   on d.OrganizationId equals og.Id into OrgDepts
                         ////do left join
                         //from od in OrgDepts.DefaultIfEmpty()
                         select new
            {
                Id = d.Id,
                Code = d.Code,
                Name = d.Name,
                Description = d.Description,
                OrganizationId = d.OrganizationId,
                Organization = d.Organization,
                Email1 = d.Email1,
                Email2 = d.Email2,
                Phone1 = d.Phone1,
                Phone2 = d.Phone2,
                UseSsl = d.UseSsl,
                HostName = d.HostName,
                Port = d.Port,
                MaxImageFileSize = d.MaxImageFileSize,
                AcceptedImageFileTypes = d.AcceptedImageFileTypes,
                MaxVideoFileSize = d.MaxVideoFileSize,
                AcceptedVideoFileTypes = d.AcceptedVideoFileTypes,
                SmsServiceProvider = d.SmsServiceProvider,
                EmailSenderName = d.EmailSenderName,
                EmailSendersEmail = d.EmailSendersEmail,
                EmailSenderPassword = d.EmailSenderPassword,
                EmailRecipientAddresses = d.EmailRecipientAddresses,
                SendSMS = d.SendSMS,
                SMSRecipientNumbers = d.SMSRecipientNumbers,
                SMSSenderName = d.SMSSenderName,
                ActivateEmailSenderSettings = d.ActivateEmailSenderSettings,
                ActivateFileSettings = d.ActivateFileSettings,
                Deleted = d.Deleted
                          //DateCreated = d.DateCreated,
                          //CreatedByUserId = inc.CreatedByUserId,
                          //DateEdited = inc.DateEdited,
                          //EditedByUserId = inc.EditedByUserId,
            })
                        .Where(x => user.UserName != "Admin" ? x.OrganizationId == user.OrganizationId && x.Deleted != true : x.Deleted != true)
                        .ToList().Select((s, index) => new DepartmentViewModel()
            {
                SerialNumber                = index + 1,
                Id                          = s.Id,
                Code                        = s.Code,
                Name                        = s.Name,
                Description                 = s.Description,
                OrganizationId              = s.OrganizationId,
                Email1                      = s.Email1,
                Email2                      = s.Email2,
                Phone1                      = s.Phone1,
                Phone2                      = s.Phone2,
                UseSsl                      = s.UseSsl,
                HostName                    = s.HostName,
                Port                        = s.Port,
                MaxImageFileSize            = s.MaxImageFileSize,
                AcceptedImageFileTypes      = s.AcceptedImageFileTypes,
                MaxVideoFileSize            = s.MaxVideoFileSize,
                AcceptedVideoFileTypes      = s.AcceptedVideoFileTypes,
                SmsServiceProvider          = s.SmsServiceProvider,
                EmailSenderName             = s.EmailSenderName,
                EmailSendersEmail           = s.EmailSendersEmail,
                EmailSenderPassword         = s.EmailSenderPassword,
                EmailRecipientAddresses     = s.EmailRecipientAddresses,
                SendSMS                     = s.SendSMS,
                SMSRecipientNumbers         = s.SMSRecipientNumbers,
                SMSSenderName               = s.SMSSenderName,
                ActivateEmailSenderSettings = s.ActivateEmailSenderSettings,
                ActivateFileSettings        = s.ActivateFileSettings
            })
                        .AsQueryable();

            if (!string.IsNullOrEmpty(queryObj.Name))
            {
                query = query.Where(v => v.Code.Contains(queryObj.Code) | v.Name.Contains(queryObj.Name) | v.Description.Contains(queryObj.Description));
            }

            //string key of the dictionary must be equal the column title in the ui. Value of the dictionary must be a valid column in db/query
            var columnsMap = new Dictionary <string, Expression <Func <DepartmentViewModel, object> > >()
            {
                ["Code"]        = v => v.Code,
                ["Name"]        = v => v.Name,
                ["Descriotion"] = v => v.Description
            };

            query = query.ApplyOrdering(queryObj, columnsMap);

            result.TotalItems = query.Count();
            // query = query.ApplyPaging(queryObj);

            result.Items = query.ToList();

            return(result);
        }
Esempio n. 20
0
 /// <summary>
 /// 查询
 /// </summary>
 /// <param name="query"></param>
 /// <returns></returns>
 public List <Department> Query(DepartmentQuery query)
 {
     return(_service.Query(query));
 }
 public PagedResult <DepartmentView> SearchPage([FromBody] DepartmentQuery queryInfo)
 {
     return(_Service.FilterPage(queryInfo));
 }
Esempio n. 22
0
 public async Task <IActionResult> Page(DepartmentQuery departmentQuery)
 {
     return(Success(await _departmentService.PageAsync(departmentQuery)));
 }
Esempio n. 23
0
 public async Task <IActionResult> Get(DepartmentQuery departmentQuery)
 {
     return(Success(await _departmentService.RetrieveAsync(departmentQuery)));
 }
 public List <DepartmentView> SearchFilter([FromBody] DepartmentQuery queryInfo)
 {
     return(_Service.Filter(queryInfo));
 }
        public List <SelectView> Select()
        {
            DepartmentQuery query = new DepartmentQuery();

            return(_Service.Select(query));
        }