Esempio n. 1
0
 public IEnumerable <CommunicationPoolEntity> SearchJobs(CommPoolSearchFilter searchFilter)
 {
     _commPoolDataAccess = new CommPoolDataAccess(_context);
     return(_commPoolDataAccess.SearchJobs(searchFilter));
 }
Esempio n. 2
0
        public ActionResult JobList(CommPoolSearchFilter searchFilter)
        {
            Logger.Info(_logMsg.Clear().SetPrefixMsg("InitSearch Job")
                        .Add("FirstName", searchFilter.FirstName).Add("LastName", searchFilter.LastName));

            try
            {
                _commonFacade = new CommonFacade();
                int?monthOfReportExport = _commonFacade.GetCacheParamByName(Constants.ParameterName.ReportExportDate).ParamValue.ToNullable <int>();

                #region "Validation"

                if (!string.IsNullOrWhiteSpace(searchFilter.FirstName) &&
                    searchFilter.FirstName.ExtractString().Length < Constants.MinLenght.SearchTerm)
                {
                    ModelState["FirstName"].Errors.Clear();
                    ModelState["FirstName"].Errors.Add(string.Format(CultureInfo.InvariantCulture, Resource.ValErr_MinLength, Constants.MinLenght.SearchTerm));
                }

                if (!string.IsNullOrWhiteSpace(searchFilter.LastName) &&
                    searchFilter.LastName.ExtractString().Length < Constants.MinLenght.SearchTerm)
                {
                    ModelState["LastName"].Errors.Clear();
                    ModelState["LastName"].Errors.Add(string.Format(CultureInfo.InvariantCulture, Resource.ValErr_MinLength, Constants.MinLenght.SearchTerm));
                }

                bool isValid = TryUpdateModel(searchFilter);

                if (!string.IsNullOrEmpty(searchFilter.DateFrom) && !searchFilter.DateFromValue.HasValue)
                {
                    isValid = false;
                    ModelState.AddModelError("txtFromDate", Resource.ValErr_InvalidDate);
                }
                else if (searchFilter.DateFromValue.HasValue)
                {
                    if (searchFilter.DateFromValue.Value > DateTime.Now.Date)
                    {
                        isValid = false;
                        ModelState.AddModelError("txtFromDate", Resource.ValErr_InvalidDate_MustLessThanToday);
                    }
                }

                if (!string.IsNullOrEmpty(searchFilter.DateTo) && !searchFilter.DateToValue.HasValue)
                {
                    isValid = false;
                    ModelState.AddModelError("txtToDate", Resource.ValErr_InvalidDate);
                }
                else if (searchFilter.DateToValue.HasValue)
                {
                    if (searchFilter.DateToValue.Value > DateTime.Now.Date)
                    {
                        isValid = false;
                        ModelState.AddModelError("txtToDate", Resource.ValErr_InvalidDate_MustLessThanToday);
                    }
                }

                if (searchFilter.DateFromValue.HasValue && searchFilter.DateToValue.HasValue &&
                    searchFilter.DateFromValue.Value > searchFilter.DateToValue.Value)
                {
                    isValid = false;
                    ModelState.AddModelError("dvDateRange", Resource.ValErr_InvalidDateRange);
                }

                // ActionDate
                if (!string.IsNullOrEmpty(searchFilter.DateFrom) && string.IsNullOrEmpty(searchFilter.DateTo))
                {
                    isValid = false;
                    ModelState.AddModelError("txtToDate", Resource.ValErr_Required);
                }
                if (string.IsNullOrEmpty(searchFilter.DateFrom) && !string.IsNullOrEmpty(searchFilter.DateTo))
                {
                    isValid = false;
                    ModelState.AddModelError("txtFromDate", Resource.ValErr_Required);
                }

                if (!string.IsNullOrEmpty(searchFilter.DateFrom) && !string.IsNullOrEmpty(searchFilter.DateTo))
                {
                    if (searchFilter.DateToValue.Value > searchFilter.DateFromValue.Value.AddMonths(monthOfReportExport.Value))
                    {
                        isValid = false;
                        ModelState.AddModelError("dvDateRange", string.Format(CultureInfo.InvariantCulture, Resource.ValError_ReportExportDuration, monthOfReportExport.Value));
                    }
                }

                #endregion

                if (isValid)
                {
                    _commPoolFacade = new CommPoolFacade();
                    JobViewModel jobVM = new JobViewModel();
                    jobVM.SearchFilter          = searchFilter;
                    jobVM.SearchFilter.User     = this.UserInfo;
                    jobVM.CommunicationPoolList = _commPoolFacade.SearchJobs(searchFilter);
                    ViewBag.PageSize            = jobVM.SearchFilter.PageSize;
                    ViewBag.PageSizeList        = _commonFacade.GetPageSizeList();

                    return(PartialView("~/Views/Job/_JobList.cshtml", jobVM));
                }

                return(Json(new
                {
                    Valid = false,
                    Error = string.Empty,
                    Errors = GetModelValidationErrors()
                }));
            }
            catch (Exception ex)
            {
                Logger.Error("Exception occur:\n", ex);
                Logger.Info(_logMsg.Clear().SetPrefixMsg("InitSearch Job").Add("Error Message", ex.Message).ToFailLogString());
                return(Error(new HandleErrorInfo(ex, this.ControllerContext.RouteData.Values["controller"].ToString(),
                                                 this.ControllerContext.RouteData.Values["action"].ToString())));
            }
        }