public ALSerListResult GetListWithPaging(WCFAuthInfoVM entity_WCFAuthInfoVM, AuditLogVM entity_SearchCriteria, int int_CurrentPage, int int_PageSize, string str_SortColumn, string str_SortDir, List <string> str_CustomFilter)
        {
            ALSerListResult ret = null;

            ret = _client.GetListWithPaging(entity_WCFAuthInfoVM, entity_SearchCriteria, int_CurrentPage, int_PageSize, str_SortColumn, str_SortDir, str_CustomFilter);
            return(ret);
        }
        public ActionResult Index(AuditLogVM selectionCriteria)
        {
            //Message Box Title -- When Error occured, Message Box would be showed.
            string str_MsgBoxTitle = MultilingualHelper.GetStringFromResource(languageKey, "AuditLogManage");

            //Define output variable(recordCount && entityList_Result)
            int recordCount = 0;

            List <AuditLogVM> entityList_Result = new List <AuditLogVM>();

            //Define wcf output object;
            ALSerListResult entity_ALSerListResult = null;

            WebCommonHelper webCommonHelper = new WebCommonHelper();

            webCommonHelper.CallWCFHelper(this, (entity_WCFAuthInfoVM) =>
            {
                entity_ALSerListResult = auditLogMgtHelper.Value.GetListWithPaging(entity_WCFAuthInfoVM, selectionCriteria, 1, PageSize, null, null, CustomFilter(selectionCriteria));
            });

            //webCommonHelper.CallWCFHelper<IAuditLogMgtSer>(this, this.HttpContext, postOffice.AuditLogMgtSerPath, (entity_IAuditLogMgtSer, entity_WCFAuthInfoVM) =>
            //{
            //    entity_ALSerListResult = entity_IAuditLogMgtSer.GetListWithPaging(entity_WCFAuthInfoVM, selectionCriteria, 1, PageSize, null, null, CustomFilter(selectionCriteria));
            //});

            //Assign data to local variable
            if (entity_ALSerListResult != null)
            {
                recordCount       = entity_ALSerListResult.Int_TotalRecordCount;
                entityList_Result = entity_ALSerListResult.EntityList_AuditLogVM;
            }

            StorePageInfo(recordCount, 1);
            StoreSelectionCriteria <AuditLogVM>(selectionCriteria);

            initFunType();

            //Pass Error To UI
            string strError = "";

            if (entity_ALSerListResult.StrList_Error.Count() > 0)
            {
                strError = string.Join("<br/>", entity_ALSerListResult.StrList_Error.ToArray());
            }

            if (entity_ALSerListResult.StrList_Error.Count > 0)
            {
                MsgInfo errorMsgInfo = new MsgInfo();
                errorMsgInfo.MsgTitle = str_MsgBoxTitle;
                errorMsgInfo.MsgDesc  = strError;
                errorMsgInfo.MsgType  = MessageType.ValidationError;
                ViewBag.ActionMessage = errorMsgInfo;
            }

            return(View(entityList_Result));
        }
Esempio n. 3
0
        public ALSerListResult GetListWithPaging(WCFAuthInfoVM entity_WCFAuthInfoVM, AuditLogVM entity_SearchCriteria, int int_CurrentPage, int int_PageSize, string str_SortColumn, string str_SortDir, List <string> str_CustomFilter)
        {
            try
            {
                //Restore Server Session
                RetrieveServerSideSession(entity_WCFAuthInfoVM);



                bool ret = false;

                List <string> strList_Error = new List <string>();

                ALSerListResult returnResult = new ALSerListResult();

                CoolPrivilegeControlContext dbContext = CoolPrivilegeControlContext.CreateContext();

                AuditLogRespository entityRepos_AL = new AuditLogRespository(dbContext, entity_BaseSession.ID);

                #region [ Check Privilege ]
                ret = CheckAccPrivilege(entity_BaseSession.ID, entity_WCFAuthInfoVM.RequestFunKey, entity_WCFAuthInfoVM.RequestFunTypeKey, ref strList_Error);
                #endregion

                returnResult.StrList_Error         = strList_Error;
                returnResult.Int_TotalRecordCount  = 0;
                returnResult.EntityList_AuditLogVM = new List <AuditLogVM>();

                LoginUserRespository LoginUserRespo = new LoginUserRespository(dbContext, entity_BaseSession.ID);

                List <LoginUserVM> entityList_LUVM = LoginUserRespo.GetLoginUser_All();

                IDictionary <string, Guid> dic_LoginUser          = new Dictionary <string, Guid>();
                IDictionary <Guid, string> dic_LoginUser_Reversal = new Dictionary <Guid, string>();

                foreach (var item in entityList_LUVM)
                {
                    dic_LoginUser[item.LoginName]   = item.ID;
                    dic_LoginUser_Reversal[item.ID] = item.LoginName;
                }

                if (ret)
                {
                    int recordCount = 0;

                    Func <List <AuditLog>, List <AuditLog> > func_OtherFilter = (entityList_AuditLog) =>
                    {
                        List <AuditLog> temp = entityList_AuditLog;
                        if (!string.IsNullOrWhiteSpace(entity_SearchCriteria.Operator))
                        {
                            List <string> strList_Key  = dic_LoginUser.Keys.Where(current => current.ToUpper().StartsWith(entity_SearchCriteria.Operator.ToUpper())).ToList();
                            List <Guid>   guidList_Key = new List <Guid>();
                            foreach (var item in strList_Key)
                            {
                                guidList_Key.Add(dic_LoginUser[item]);
                            }

                            if (guidList_Key.Count > 0)
                            {
                                temp = temp.Where(current => guidList_Key.Contains(current.AL_UserID)).ToList();
                            }
                            else
                            {
                                temp.Clear();
                            }
                        }

                        if (!string.IsNullOrWhiteSpace(entity_SearchCriteria.AL_EventType))
                        {
                            if ("Create".ToUpper().StartsWith(entity_SearchCriteria.AL_EventType.ToUpper()))
                            {
                                temp = temp.Where(current => current.AL_EventType == OperationType.A.ToString()).ToList();
                            }
                            else if ("Edit".ToUpper().StartsWith(entity_SearchCriteria.AL_EventType.ToUpper()))
                            {
                                temp = temp.Where(current => current.AL_EventType == OperationType.M.ToString()).ToList();
                            }
                            else if ("Delete".ToUpper().StartsWith(entity_SearchCriteria.AL_EventType.ToUpper()))
                            {
                                temp = temp.Where(current => current.AL_EventType == OperationType.D.ToString()).ToList();
                            }
                        }

                        temp = temp.Where(current => DateTimeUtility.ValidateInputDatetime(current.AL_CreateDate, entity_SearchCriteria.DateFrom, entity_SearchCriteria.DateTo)).ToList();
                        return(temp);
                    };

                    List <AuditLogVM> vmList = entityRepos_AL.GetEntityListByPage(entity_SearchCriteria, int_CurrentPage, int_PageSize, str_SortColumn, str_SortDir, out recordCount, str_CustomFilter, func_OtherFilter, (entityList_VM) =>
                    {
                        foreach (var item in entityList_VM)
                        {
                            if (dic_LoginUser_Reversal.ContainsKey(item.AL_UserID))
                            {
                                item.Operator = dic_LoginUser_Reversal[item.AL_UserID];
                            }
                            if (item.AL_EventType == OperationType.A.ToString())
                            {
                                item.AL_EventType = "Create";
                            }
                            else if (item.AL_EventType == OperationType.M.ToString())
                            {
                                item.AL_EventType = "Edit";
                            }
                            else if (item.AL_EventType == OperationType.D.ToString())
                            {
                                item.AL_EventType = "Delete";
                            }
                        }
                        return(entityList_VM);
                    });

                    returnResult.EntityList_AuditLogVM = vmList;
                    returnResult.Int_TotalRecordCount  = recordCount;
                }

                return(returnResult);
            }
            catch (Exception ex)
            {
                throw new FaultException <WCFErrorContract>(new WCFErrorContract(ex), ex.Message);
            }
        }
        public ActionResult Export(FormCollection collection)
        {
            string sort    = "";
            string sortDir = "";

            if (collection.AllKeys.Contains("sort"))
            {
                sort = collection["sort"];
            }

            if (collection.AllKeys.Contains("sortDir"))
            {
                sortDir = collection["sortDir"];
            }

            //Message Box Title -- When Error occured, Message Box would be showed.
            string str_MsgBoxTitle = MultilingualHelper.GetStringFromResource(languageKey, "AuditLogManage_Export");

            ExportFileJsonResult commonJsonResult = new ExportFileJsonResult();

            commonJsonResult.MsgTitle = str_MsgBoxTitle;

            AuditLogVM selectionCriteria = new AuditLogVM();

            if (TempData.ContainsKey(SelectionCriteriaKey))
            {
                selectionCriteria = (AuditLogVM)TempData[SelectionCriteriaKey];
            }

            TempData[SelectionCriteriaKey] = selectionCriteria;
            ViewBag.SelectionCriteria      = selectionCriteria;

            int recordCount = 0;

            List <AuditLogVM> entityList_Result = new List <AuditLogVM>();

            //Define wcf output object;
            ALSerListResult entity_ALSerListResult = null;

            WebCommonHelper webCommonHelper = new WebCommonHelper();

            webCommonHelper.CallWCFHelper(this, (entity_WCFAuthInfoVM) =>
            {
                entity_ALSerListResult = auditLogMgtHelper.Value.GetListWithPaging(entity_WCFAuthInfoVM, selectionCriteria, 1, int.MaxValue, sort, sortDir, CustomFilter(selectionCriteria));
            });

            //webCommonHelper.CallWCFHelper<IAuditLogMgtSer>(this, this.HttpContext, postOffice.AuditLogMgtSerPath, (entity_IAuditLogMgtSer, entity_WCFAuthInfoVM) =>
            //{
            //    entity_ALSerListResult = entity_IAuditLogMgtSer.GetListWithPaging(entity_WCFAuthInfoVM, selectionCriteria, 1, int.MaxValue, sort, sortDir, CustomFilter(selectionCriteria));
            //});

            //Assign data to local variable
            if (entity_ALSerListResult != null)
            {
                recordCount       = entity_ALSerListResult.Int_TotalRecordCount;
                entityList_Result = entity_ALSerListResult.EntityList_AuditLogVM;
            }

            if (entityList_Result != null && entityList_Result.Count > 0)
            {
                RendDtlToExcelPolicy rendDtlToExcelPolicy = new RendDtlToExcelPolicy();

                List <string> strList_DisplayColumn = new List <string>();
                strList_DisplayColumn.Add("Operator");
                strList_DisplayColumn.Add("AL_CreateDate");
                strList_DisplayColumn.Add("AL_TableName");
                strList_DisplayColumn.Add("AL_EventType");
                strList_DisplayColumn.Add("AL_OriginalValue");
                strList_DisplayColumn.Add("AL_NewValue");

                Dictionary <string, string> dic_OutputMapping = new Dictionary <string, string>()
                {
                    { "Operator", MultilingualHelper.GetStringFromResource("Operator") },
                    { "AL_CreateDate", MultilingualHelper.GetStringFromResource("Date") },
                    { "AL_TableName", MultilingualHelper.GetStringFromResource("TableName") },
                    { "AL_EventType", MultilingualHelper.GetStringFromResource("OperationType") },
                    { "AL_OriginalValue", MultilingualHelper.GetStringFromResource("OriginalValue") },
                    { "AL_NewValue", MultilingualHelper.GetStringFromResource("NewValue") },
                    { "AL_RecordKey", MultilingualHelper.GetStringFromResource("RecordKey") },
                };

                MemoryStream memoryStream = rendDtlToExcelPolicy.ExportEntityListToXlsx <AuditLogVM>("AuditLog", entityList_Result, true, 1, 1, strList_DisplayColumn, dic_OutputMapping);

                string Key = Guid.NewGuid().ToString();

                TempData[Key] = memoryStream;

                commonJsonResult.ReturnUrl = Url.Action("ExportExcel", "Export", new { Area = "Common" }, Request.Url.Scheme);

                commonJsonResult.Success = true;

                commonJsonResult.Key            = Key;
                commonJsonResult.OutputFileName = "AuditLog" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xlsx";

                return(Json(commonJsonResult));
            }
            else
            {
                commonJsonResult.ReturnUrl = Url.Action("Index", "AuditLogManage", new { Area = "AccessControl" }, Request.Url.Scheme);
                commonJsonResult.Success   = false;

                MsgInfo errorMsgInfo = new MsgInfo();
                errorMsgInfo.MsgTitle      = str_MsgBoxTitle;
                errorMsgInfo.MsgDesc       = MultilingualHelper.GetStringFromResource(languageKey, "E019");
                errorMsgInfo.MsgType       = MessageType.ValidationError;
                TempData[ActionMessageKey] = errorMsgInfo;
                return(Json(commonJsonResult));
            }
        }