Пример #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);
        }
Пример #2
0
        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);
        }
        public IActionResult Filter(string name)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var departmentfilter = _departmentRepository.Filter(name);

            try
            {
                if (departmentfilter == null)
                {
                    return(Content("The department is not found!"));
                }
                return(Ok(departmentfilter));
            }
            catch
            {
                return(BadRequest(ModelState)); //or can throw new Exception
            }
        }