Ejemplo n.º 1
0
        public ActionResult AutoCompleteSearchSubArea(string keyword, int?areaId, bool?isAllStatus)
        {
            Logger.Info(_logMsg.Clear().SetPrefixMsg("Auto Complete :: Search SubArea").Add("Keyword", keyword)
                        .Add("AreaId", areaId).Add("IsAllStatus", isAllStatus).ToInputLogString());

            try
            {
                _srFacade = new ServiceRequestFacade();
                List <SubAreaItemEntity> result = _srFacade.AutoCompleteSearchSubArea(keyword, areaId, AutoCompleteMaxResult, isAllStatus);
                return(Json(result.Select(r => new
                {
                    r.SubAreaId,
                    r.SubAreaName
                })));
            }
            catch (Exception ex)
            {
                Logger.Error("Exception occur:\n", ex);
                Logger.Info(_logMsg.Clear().SetPrefixMsg("Auto Complete :: Search SubArea").Add("Error Message", ex.Message).ToFailLogString());
                return(Error(new HandleErrorInfo(ex, this.ControllerContext.RouteData.Values["controller"].ToString(),
                                                 this.ControllerContext.RouteData.Values["action"].ToString())));
            }
        }
Ejemplo n.º 2
0
        public ActionResult AutoCompleteSearchAreaOnMapping(string keyword, int?campaignServiceId, int?subAreaId, int?typeId)
        {
            Logger.Info(_logMsg.Clear().SetPrefixMsg("Auto Complete :: Search Area (on Mapping)").Add("Keyword", keyword)
                        .Add("CampaignServiceId", campaignServiceId).Add("SubAreaId", subAreaId).Add("TypeId", typeId).ToInputLogString());

            try
            {
                _srFacade = new ServiceRequestFacade();
                List <AreaItemEntity> result = _srFacade.AutoCompleteSearchAreaOnMapping(keyword, campaignServiceId, subAreaId, typeId, AutoCompleteMaxResult);
                return(Json(result.Select(r => new
                {
                    r.AreaId,
                    r.AreaName
                })));
            }
            catch (Exception ex)
            {
                Logger.Error("Exception occur:\n", ex);
                Logger.Info(_logMsg.Clear().SetPrefixMsg("Auto Complete :: Search Area (on Mapping)").Add("Error Message", ex.Message).ToFailLogString());
                return(Error(new HandleErrorInfo(ex, this.ControllerContext.RouteData.Values["controller"].ToString(),
                                                 this.ControllerContext.RouteData.Values["action"].ToString())));
            }
        }
Ejemplo n.º 3
0
        public ActionResult AutoCompleteSearchUserWithJobOnHand(string keyword, int branchId)
        {
            Logger.Info(_logMsg.Clear().SetPrefixMsg("Auto Complete :: Search User with Job On Hand").Add("Keyword", keyword)
                        .Add("BranchId", branchId).ToInputLogString());

            try
            {
                _srFacade = new ServiceRequestFacade();
                List <UserEntity> result = _srFacade.AutoCompleteSearchUserWithJobOnHand(keyword, branchId, AutoCompleteMaxResult);
                return(Json(result.Select(r => new
                {
                    r.UserId,
                    UserDisplayName = r.FullName + " (" + (r.JobOnHand ?? 0) + ")"
                })));
            }
            catch (Exception ex)
            {
                Logger.Error("Exception occur:\n", ex);
                Logger.Info(_logMsg.Clear().SetPrefixMsg("Auto Complete :: Search User with Job On Hand").Add("Error Message", ex.Message).ToFailLogString());
                return(Error(new HandleErrorInfo(ex, this.ControllerContext.RouteData.Values["controller"].ToString(),
                                                 this.ControllerContext.RouteData.Values["action"].ToString())));
            }
        }
Ejemplo n.º 4
0
 public ActionResult AutoCompleteSearchProductWithExceptions(AutoCompleteSearchProductInputModel model)
 {
     Logger.Info(_logMsg.Clear().SetPrefixMsg("Auto Complete :: Search Product")
                 .Add("Keyword", model.Keyword)
                 .Add("ExceptionIds", string.Join(", ", model.ExceptProductIds)));
     try
     {
         _srFacade = new ServiceRequestFacade();
         List <ProductEntity> result = _srFacade.AutoCompleteSearchProduct(model.Keyword, model.ExceptProductIds, AutoCompleteMaxResult);
         return(Json(result.Select(r => new
         {
             r.ProductId,
             r.ProductName,
         })));
     }
     catch (Exception ex)
     {
         Logger.Error("Exception occur:\n", ex);
         Logger.Info(_logMsg.Clear().SetPrefixMsg("Auto Complete :: Search Product").Add("Error Message", ex.Message).ToFailLogString());
         return(Error(new HandleErrorInfo(ex, this.ControllerContext.RouteData.Values["controller"].ToString(),
                                          this.ControllerContext.RouteData.Values["action"].ToString())));
     }
 }
Ejemplo n.º 5
0
        public ActionResult AutoCompleteSearchProductForQuestionGroup(string keyword, int?productGroupId, int?campaignServiceId, bool?isAllStatus)
        {
            Logger.Info(_logMsg.Clear().SetPrefixMsg("Auto Complete :: Search Product for QuestionGroup").Add("Keyword", keyword)
                        .Add("ProductGroupId", productGroupId).Add("CampaignServiceId", campaignServiceId).Add("IsAllStatus", isAllStatus).ToInputLogString());

            try
            {
                _srFacade = new ServiceRequestFacade();
                List <ProductEntity> result = _srFacade.AutoCompleteSearchProductForQuestionGroup(keyword, productGroupId, AutoCompleteMaxResult, campaignServiceId);
                return(Json(result.Select(r => new
                {
                    r.ProductId,
                    r.ProductName,
                    r.ProductGroupName
                })));
            }
            catch (Exception ex)
            {
                Logger.Error("Exception occur:\n", ex);
                Logger.Info(_logMsg.Clear().SetPrefixMsg("Auto Complete :: Search Product for QuestionGroup").Add("Error Message", ex.Message).ToFailLogString());
                return(Error(new HandleErrorInfo(ex, this.ControllerContext.RouteData.Values["controller"].ToString(),
                                                 this.ControllerContext.RouteData.Values["action"].ToString())));
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Batch Process
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public ReSubmitActivityToCBSHPSystemTaskResponse ReSubmitActivityToCBSHPSystem(string username, string password)
        {
            ThreadContext.Properties["EventClass"]    = ApplicationHelpers.GetCurrentMethod(1);
            ThreadContext.Properties["RemoteAddress"] = ApplicationHelpers.GetClientIP();
            //ThreadContext.Properties["UserID"] = "CSM_SCHEDTASK";
            if (!string.IsNullOrWhiteSpace(username))
            {
                ThreadContext.Properties["UserID"] = username.ToUpperInvariant();
            }

            long     elapsedTime   = 0;
            string   errorMessage  = string.Empty;
            DateTime schedDateTime = DateTime.Now;
            ReSubmitActivityToCBSHPSystemTaskResponse taskResponse = null;

            _auditLog           = new AuditLogEntity();
            _auditLog.Module    = Constants.Module.Batch;
            _auditLog.Action    = Constants.AuditAction.ReSubmitActivityToCBSHPSystem;
            _auditLog.IpAddress = ApplicationHelpers.GetClientIP();

            System.Diagnostics.Stopwatch stopwatch = System.Diagnostics.Stopwatch.StartNew();
            _logger.Debug("-- Start Cron Job --:--Get ReSubmitActivityToCBSHPSystem--");

            #region "BatchProcess Start"

            if (AppLog.BatchProcessStart(Constants.BatchProcessCode.ReSubmitActivityToCBSHPSystem, schedDateTime) == false)
            {
                _logger.Info("I:--NOT PROCESS--:--ReSubmitActivityToCBSHPSystem--");

                stopwatch.Stop();
                elapsedTime = stopwatch.ElapsedMilliseconds;
                _logger.Debug("-- Finish Cron Job --:ElapsedMilliseconds/" + elapsedTime);

                taskResponse = new ReSubmitActivityToCBSHPSystemTaskResponse
                {
                    SchedDateTime  = schedDateTime,
                    ElapsedTime    = elapsedTime,
                    StatusResponse = new CSM.Service.Messages.Common.StatusResponse
                    {
                        Status = Constants.StatusResponse.NotProcess
                    }
                };

                return(taskResponse);
            }

            #endregion

            //_logger.Debug("-- Start Cron Job --:--Get ReSubmitActivityToCBSHPSystem--");

            if (!ApplicationHelpers.Authenticate(username, password))
            {
                errorMessage = "Username and/or Password Invalid.";
                taskResponse = new ReSubmitActivityToCBSHPSystemTaskResponse
                {
                    SchedDateTime  = schedDateTime,
                    StatusResponse = new CSM.Service.Messages.Common.StatusResponse
                    {
                        Status      = Constants.StatusResponse.Failed,
                        ErrorCode   = string.Empty,
                        Description = errorMessage
                    }
                };

                _logger.InfoFormat("O:--LOGIN--:Error Message/{0}", errorMessage);
                //AppLog.AuditLog(_auditLog, LogStatus.Fail, "Username and/or Password Invalid.");
                return(taskResponse);
            }

            try
            {
                _logger.Info("I:--START--:--ReSubmitActivityToCBSHPSystem--");

                #region "Process Batch"

                var countSuccess = 0;
                var countError   = 0;

                _srFacade = new ServiceRequestFacade();
                _srFacade.ReSubmitActivityToCBSHPSystem(ref countSuccess, ref countError);

                #endregion

                _logger.Info("O:--SUCCESS--:--ReSubmitActivityToCBSHPSystem--");

                stopwatch.Stop();
                elapsedTime = stopwatch.ElapsedMilliseconds;
                _logger.Debug("-- Finish Cron Job --:ElapsedMilliseconds/" + elapsedTime);

                StringBuilder taskResult = new StringBuilder("");
                taskResult.Append(string.Format("Username = {0}\n", username));
                taskResult.Append(string.Format("SchedDateTime = {0}\n", schedDateTime));
                taskResult.Append(string.Format("ElapsedTime = {0}\n", elapsedTime));
                taskResult.Append(string.Format("Count Success = {0}\n", countSuccess));
                taskResult.Append(string.Format("Count Error = {0}\n", countError));
                taskResult.Append(string.Format("Total = {0}\n", countSuccess + countError));

                AppLog.AuditLog(_auditLog, ((countError > 0) ? LogStatus.Fail : LogStatus.Success), taskResult.ToString());

                taskResponse = new ReSubmitActivityToCBSHPSystemTaskResponse
                {
                    SchedDateTime  = schedDateTime,
                    ElapsedTime    = elapsedTime,
                    StatusResponse = new CSM.Service.Messages.Common.StatusResponse
                    {
                        Status = (countError > 0) ? Constants.StatusResponse.Failed : Constants.StatusResponse.Success
                    },
                    NumOfComplete = countSuccess,
                    NumOfError    = countError,
                    NumOfTotal    = countSuccess + countError
                };

                return(taskResponse);
            }
            catch (Exception ex)
            {
                _logger.InfoFormat("O:--FAILED--:--ReSubmitActivityToCBSHPSystem--:--Error Message/{0}", ex.Message);
                _logger.Error("Exception occur:\n", ex);

                stopwatch.Stop();
                elapsedTime = stopwatch.ElapsedMilliseconds;
                _logger.Debug("-- Finish Cron Job --:ElapsedMilliseconds/" + elapsedTime);

                AppLog.AuditLog(_auditLog, LogStatus.Fail, ex.Message);

                taskResponse = new ReSubmitActivityToCBSHPSystemTaskResponse
                {
                    SchedDateTime  = schedDateTime,
                    ElapsedTime    = elapsedTime,
                    StatusResponse = new CSM.Service.Messages.Common.StatusResponse
                    {
                        Status      = Constants.StatusResponse.Failed,
                        ErrorCode   = string.Empty,
                        Description = "Failed to ReSubmitActivityToCBSHPSystem"
                    }
                };

                return(taskResponse);
            }
            finally
            {
                // Send mail to system administrator
                ReSubmitActivityToCBSHPSendMail(taskResponse);

                #region "BatchProcess End"

                if (taskResponse != null && taskResponse.StatusResponse != null &&
                    taskResponse.StatusResponse.Status != Constants.StatusResponse.NotProcess)
                {
                    int batchStatus = (taskResponse.StatusResponse.Status == Constants.StatusResponse.Success)
                        ? Constants.BatchProcessStatus.Success
                        : Constants.BatchProcessStatus.Fail;

                    DateTime endTime     = taskResponse.SchedDateTime.AddMilliseconds(taskResponse.ElapsedTime);
                    TimeSpan processTime = endTime.Subtract(taskResponse.SchedDateTime);

                    string processDetail = !string.IsNullOrEmpty(taskResponse.StatusResponse.Description)
                       ? taskResponse.StatusResponse.Description
                       : taskResponse.ToString();

                    AppLog.BatchProcessEnd(Constants.BatchProcessCode.ReSubmitActivityToCBSHPSystem, batchStatus, endTime, processTime, processDetail);
                }

                #endregion
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Batch Process
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public ReSubmitActivityToCBSHPSystemTaskResponse ReSubmitActivityToCBSHPSystem(string username, string password)
        {
            ThreadContext.Properties["EventClass"]    = ApplicationHelpers.GetCurrentMethod(1);
            ThreadContext.Properties["RemoteAddress"] = ApplicationHelpers.GetClientIP();
            ThreadContext.Properties["UserID"]        = "CSM_SCHEDTASK";

            long     elapsedTime   = 0;
            DateTime schedDateTime = DateTime.Now;

            _auditLog           = new AuditLogEntity();
            _auditLog.Module    = Constants.Module.Batch;
            _auditLog.Action    = Constants.AuditAction.ReSubmitActivityToCBSHPSystem;
            _auditLog.IpAddress = ApplicationHelpers.GetClientIP();

            System.Diagnostics.Stopwatch stopwatch = System.Diagnostics.Stopwatch.StartNew();
            _logger.Debug("-- Start Cron Job --:--Get ReSubmitActivityToCBSHPSystem--");

            if (!ApplicationHelpers.Authenticate(username, password))
            {
                _logger.DebugFormat("O:--LOGIN--:Error Message/{0}", "Username and/or Password Invalid.");

                AppLog.AuditLog(_auditLog, LogStatus.Fail, "Username and/or Password Invalid.");
            }
            try
            {
                _logger.Info("I:--START--:--ReSubmitActivityToCBSHPSystem--");

                #region "Process Batch"

                var countSuccess = 0;
                var countError   = 0;

                _srFacade = new ServiceRequestFacade();
                _srFacade.ReSubmitActivityToCBSHPSystem(ref countSuccess, ref countError);

                #endregion

                _logger.Info("I:--SUCCESS--:--ReSubmitActivityToCBSHPSystem--");

                stopwatch.Stop();
                elapsedTime = stopwatch.ElapsedMilliseconds;
                _logger.Debug("-- Finish Cron Job --:ElapsedMilliseconds/" + elapsedTime);

                StringBuilder taskResult = new StringBuilder("");
                taskResult.Append(string.Format("Username = {0}\n", username));
                taskResult.Append(string.Format("SchedDateTime = {0}\n", schedDateTime));
                taskResult.Append(string.Format("ElapsedTime = {0}\n", elapsedTime));
                taskResult.Append(string.Format("Count Success = {0}\n", countSuccess));
                taskResult.Append(string.Format("Count Error = {0}\n", countError));
                taskResult.Append(string.Format("Total = {0}\n", countSuccess + countError));

                AppLog.AuditLog(_auditLog, LogStatus.Success, taskResult.ToString());

                return(new ReSubmitActivityToCBSHPSystemTaskResponse
                {
                    SchedDateTime = schedDateTime,
                    ElapsedTime = elapsedTime,
                    StatusResponse = new CSM.Service.Messages.Common.StatusResponse
                    {
                        Status = Constants.StatusResponse.Success
                    },
                    NumOfComplete = countSuccess,
                    NumOfError = countError,
                    NumOfTotal = countSuccess + countError,
                });
            }
            catch (Exception ex)
            {
                _logger.InfoFormat("O:--FAILED--:--ReSubmitActivityToCBSHPSystem--:--Error Message/{0}", ex.Message);
                _logger.Error("Exception occur:\n", ex);

                stopwatch.Stop();
                elapsedTime = stopwatch.ElapsedMilliseconds;
                _logger.Debug("-- Finish Cron Job --:ElapsedMilliseconds/" + elapsedTime);

                AppLog.AuditLog(_auditLog, LogStatus.Fail, ex.Message);

                return(new ReSubmitActivityToCBSHPSystemTaskResponse
                {
                    SchedDateTime = schedDateTime,
                    ElapsedTime = elapsedTime,
                    StatusResponse = new CSM.Service.Messages.Common.StatusResponse
                    {
                        Status = Constants.StatusResponse.Failed,
                        ErrorCode = string.Empty,
                        Description = "Fail to ReSubmitActivityToCBSHPSystem"
                    },
                });
            }
        }