Example #1
0
        public string GetParameter(string paramName)
        {
            _commonFacade = new CommonFacade();
            ParameterEntity param = _commonFacade.GetCacheParamByName(paramName);

            return(param != null ? param.ParamValue : string.Empty);
        }
Example #2
0
        private int GetMaxRetrieveMail()
        {
            _commonFacade = new CommonFacade();
            ParameterEntity param = _commonFacade.GetCacheParamByName(Constants.ParameterName.MaxRetrieveMail);

            return(param != null?param.ParamValue.ToNullable <int>().Value : 200);
        }
Example #3
0
        public ActionResult InitEdit(string jsonData)
        {
            _commonFacade = new CommonFacade();

            #region "For show in hint"

            ParameterEntity param = _commonFacade.GetCacheParamByName(Constants.ParameterName.RegexFileExt);
            ParameterEntity paramSingleFileSize = _commonFacade.GetCacheParamByName(Constants.ParameterName.SingleFileSize);

            int?limitSingleFileSize = paramSingleFileSize.ParamValue.ToNullable <int>();
            var singleLimitSize     = limitSingleFileSize.HasValue ? (limitSingleFileSize / 1048576) : 0;
            ViewBag.UploadLimitType = string.Format(CultureInfo.InvariantCulture, param.ParamDesc, singleLimitSize);

            #endregion

            List <DocumentTypeEntity> docTypeList = null;
            var attachVM = JsonConvert.DeserializeObject <AttachViewModel>(jsonData);

            if (attachVM.ListIndex != null)
            {
                AttachmentEntity selectedAttach = attachVM.AttachmentList[attachVM.ListIndex.Value];
                attachVM.Filename   = selectedAttach.Filename;
                attachVM.DocName    = selectedAttach.Name;
                attachVM.DocDesc    = selectedAttach.Description;
                attachVM.ExpiryDate = selectedAttach.ExpiryDateDisplay;
                docTypeList         = _commonFacade.GetDocumentTypeList(selectedAttach.AttachTypeList, Constants.DocumentCategory.Announcement);
            }
            else
            {
                docTypeList = _commonFacade.GetActiveDocumentTypes(Constants.DocumentCategory.Announcement);
            }

            if (docTypeList != null)
            {
                attachVM.DocTypeCheckBoxes = docTypeList.Select(x => new CheckBoxes
                {
                    Value   = x.DocTypeId.ToString(),
                    Text    = x.Name,
                    Checked = x.IsChecked
                }).ToList();
            }

            return(PartialView("~/Views/Attachment/_AttachEdit.cshtml", attachVM));
        }
        private DoNotCallByCustomerEntity MapCustomerEntity <T>(T request, DoNotCallInterfaceValidateResult validateResult)
            where T : DoNotCallTransactionInput
        {
            DateTime now = DateTime.Now;

            _commonFacade = new CommonFacade();
            string   neverExpireDate         = _commonFacade.GetCacheParamByName("DNC_NEVER_EXPIRE_DATE").ParamValue;
            DateTime nonExpireDate           = DateTimeHelpers.ParseDateTime(neverExpireDate, "yyyy-MM-dd").Value;
            bool     isActive                = request.Status == Constants.DigitTrue;
            DateTime expireDate              = isActive ? request.ExpiryDate.HasValue ? request.ExpiryDate.Value : now.Date.AddYears(1).Date : now.Date; // if inactive set expire date to today
            bool     isBlockAllSalesProducts = validateResult.IsBlockAllSalesProducts;
            bool     isBlockAllInfoProducts  = validateResult.IsBlockAllInfoProducts;
            List <DoNotCallActivityProductInput> blockSalesProducts = isBlockAllSalesProducts ? new List <DoNotCallActivityProductInput>()
                                                                           : validateResult.ActivityProducts
                                                                      .Where(x => x.BlockType == Constants.ActivityProductTypeSales)
                                                                      .ToList();
            List <DoNotCallActivityProductInput> blockInfoProducts = isBlockAllInfoProducts ? new List <DoNotCallActivityProductInput>()
                                                                          : validateResult.ActivityProducts
                                                                     .Where(x => x.BlockType == Constants.ActivityProductTypeInformation)
                                                                     .ToList();

            // check user exists?
            _userFacade = new UserFacade();
            UserEntity user = _userFacade.GetUserByLogin(request.UpdateUser) ?? new UserEntity
            {
                UserId   = 0,
                Username = request.UpdateUser
            };

            var entity = new DoNotCallByCustomerEntity
            {
                CurrentUserId        = user.UserId,
                CurrentUsername      = user.Username,
                CurrentUserIpAddress = ApplicationHelpers.GetClientIP(),
                BasicInfo            = new DoNotCallBasicInfoModel
                {
                    FirstName     = request.FirstName,
                    LastName      = request.LastName,
                    TransactionId = validateResult.TransactionId ?? 0,
                    EffectiveDate = now.Date,
                    CreateDate    = now,
                    UpdateDate    = now,
                    IsNeverExpire = expireDate.Date == nonExpireDate.Date,
                    ExpireDate    = expireDate,
                    FromSystem    = request.SystemCode,
                    IsActive      = isActive,
                    Remark        = request.Remark
                },
                CardInfo = new DoNotCallCardInfoModel
                {
                    CardNo             = request.CardNo,
                    SubscriptionTypeId = validateResult.SubscriptionTypeId.Value
                },
                ContactDetail = new DoNotCallContactModel
                {
                    Email = new DoNotCallEmail
                    {
                        EmailList = request.EmailList?.Select(email => new DoNotCallEmailModel
                        {
                            Email          = email.Email,
                            Id             = email.Id.HasValue? email.Id.Value: 0,
                            IsDeleted      = email.IsActive == Constants.FlagN,
                            LastUpdateDate = now
                        }).ToList() ?? new List <DoNotCallEmailModel>()
                    },
                    Telephone = new DoNotCallTelephone
                    {
                        TelephoneList = request.TelephoneList?.Select(phoneNo => new DoNotCallTelephoneModel
                        {
                            PhoneNo        = phoneNo.PhoneNo,
                            Id             = phoneNo.Id.HasValue? phoneNo.Id.Value: 0,
                            IsDeleted      = phoneNo.IsActive == Constants.FlagN,
                            LastUpdateDate = now
                        }).ToList() ?? new List <DoNotCallTelephoneModel>()
                    }
                },
                BlockSales = new DoNotCallBlockSalesModel
                {
                    IsBlockAllSalesProducts = isBlockAllSalesProducts,
                    IsBlockSalesEmail       = request.SalesBlockInfo.BlockEmail == Constants.DigitTrue,
                    IsBlockSalesSms         = request.SalesBlockInfo.BlockSMS == Constants.DigitTrue,
                    IsBlockSalesTelephone   = request.SalesBlockInfo.BlockTelephone == Constants.DigitTrue,
                    BlockSalesProductList   = blockSalesProducts.Select(product => new DoNotCallProductModel
                    {
                        ActivityProductType = Constants.ActivityProductTypeSales,
                        CreateDate          = now,
                        IsDeleted           = product.IsActive == Constants.FlagN,
                        Id = product.ProductId.Value,
                        ActivityProductId = product.ActivityProductId,
                        ProductId         = product.ProductId.HasValue ? product.ProductId.Value: 0,
                        UpdateDate        = now
                    }).ToList() ?? new List <DoNotCallProductModel>()
                },
                BlockInformation = new DoNotCallBlockInformationModel
                {
                    IsBlockAllInfoProducts = isBlockAllInfoProducts,
                    IsBlockInfoEmail       = request.InformationBlockInfo.BlockEmail == Constants.DigitTrue,
                    IsBlockInfoSms         = request.InformationBlockInfo.BlockSMS == Constants.DigitTrue,
                    IsBlockInfoTelephone   = request.InformationBlockInfo.BlockTelephone == Constants.DigitTrue,
                    BlockInfoProductList   = blockInfoProducts.Select(product => new DoNotCallProductModel
                    {
                        ActivityProductType = Constants.ActivityProductTypeInformation,
                        CreateDate          = now,
                        IsDeleted           = product.IsActive == Constants.FlagN,
                        Id = product.ProductId.Value,
                        ActivityProductId = product.ActivityProductId,
                        ProductId         = product.ProductId.HasValue ? product.ProductId.Value: 0,
                        UpdateDate        = now
                    }).ToList() ?? new List <DoNotCallProductModel>()
                }
            };

            return(entity);
        }
Example #5
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())));
            }
        }
Example #6
0
        public ActionResult Edit(AttachViewModel attachVM)
        {
            Logger.Info(_logMsg.Clear().SetPrefixMsg("List Attachment").Add("DocName", attachVM.DocName)
                        .Add("DocDesc", attachVM.DocDesc).ToInputLogString());

            AttachmentEntity attach = attachVM.ListIndex != null ? attachVM.AttachmentList[attachVM.ListIndex.Value] : new AttachmentEntity();
            int?oldFileSize         = 0; // เพื่อเช็คขนาดไฟล์รวม

            if (attach.AttachmentId != 0)
            {
                oldFileSize = attach.FileSize; // เพื่อเช็คขนาดไฟล์รวม
                ModelState.Remove("FileAttach");
            }

            if (ModelState.IsValid)
            {
                var file = attachVM.FileAttach;
                attach.Name        = attachVM.DocName;
                attach.Description = attachVM.DocDesc;
                attach.ExpiryDate  = attachVM.ExpiryDate.ParseDateTime(Constants.DateTimeFormat.DefaultShortDate);

                var selectedAttachType = attachVM.DocTypeCheckBoxes.Where(x => x.Checked == true)
                                         .Select(x => new AttachmentTypeEntity
                {
                    DocTypeId    = x.Value.ToNullable <int>(),
                    CreateUserId = this.UserInfo.UserId
                }).ToList();

                if (attach.AttachTypeList != null && attach.AttachTypeList.Count > 0)
                {
                    var prevAttachTypes = (from at in attach.AttachTypeList
                                           select new AttachmentTypeEntity
                    {
                        AttachmentId = at.AttachmentId,
                        Code = at.Code,
                        Name = at.Name,
                        DocTypeId = at.DocTypeId,
                        IsDelete = !selectedAttachType.Select(x => x.DocTypeId).Contains(at.DocTypeId),
                        Status = at.Status,
                        CreateUserId = this.UserInfo.UserId
                    }).ToList();

                    var dupeAttachTypes = new List <AttachmentTypeEntity>(selectedAttachType);
                    dupeAttachTypes.AddRange(prevAttachTypes);

                    var duplicates = dupeAttachTypes.GroupBy(x => new { x.DocTypeId })
                                     .Where(g => g.Count() > 1)
                                     .Select(g => (object)g.Key.DocTypeId);

                    if (duplicates.Any())
                    {
                        //Logger.Info(_logMsg.Clear().SetPrefixMsg("Duplicate ID in list")
                        //    .Add("IDs", StringHelpers.ConvertListToString(duplicates.ToList(), ",")).ToInputLogString());
                        prevAttachTypes.RemoveAll(x => duplicates.Contains(x.DocTypeId));
                    }

                    selectedAttachType.AddRange(prevAttachTypes);
                }

                attach.AttachTypeList = selectedAttachType;

                // Verify that the user selected a file
                if (file != null && file.ContentLength > 0)
                {
                    _commonFacade = new CommonFacade();
                    ParameterEntity paramSingleFileSize = _commonFacade.GetCacheParamByName(Constants.ParameterName.SingleFileSize);
                    ParameterEntity paramTotalFileSize  = _commonFacade.GetCacheParamByName(Constants.ParameterName.TotalFileSize);
                    int?            limitSingleFileSize = paramSingleFileSize.ParamValue.ToNullable <int>();
                    int?            limitTotalFileSize  = paramTotalFileSize.ParamValue.ToNullable <int>();

                    if (file.ContentLength > limitSingleFileSize.Value)
                    {
                        ModelState.AddModelError("FileAttach", string.Format(CultureInfo.InvariantCulture, Resource.ValError_SingleFileSizeExceedMaxLimit, (limitSingleFileSize.Value / 1048576)));
                        goto Outer;
                    }

                    int?totalSize = attachVM.AttachmentList.Where(x => x.IsDelete == false).Sum(x => x.FileSize);
                    totalSize -= oldFileSize; // กรณีแก้ไข จะลบขนาดไฟล์เก่าออก
                    totalSize += file.ContentLength;

                    if (totalSize > limitTotalFileSize.Value)
                    {
                        ModelState.AddModelError("FileAttach", string.Format(CultureInfo.InvariantCulture, Resource.ValError_TotalFileSizeExceedMaxLimit, (limitTotalFileSize.Value / 1048576)));
                        goto Outer;
                    }

                    // extract only the filename
                    var fileName = Path.GetFileName(file.FileName);
                    //const string regexPattern = @"^.*\.(jpg|jpeg|doc|docx|xls|xlsx|ppt|txt)$";

                    ParameterEntity param = _commonFacade.GetCacheParamByName(Constants.ParameterName.RegexFileExt);
                    Match           match = Regex.Match(fileName, param.ParamValue, RegexOptions.IgnoreCase);

                    if (!match.Success)
                    {
                        ModelState.AddModelError("FileAttach", Resource.ValError_FileExtension);
                        goto Outer;
                    }

                    string fileExtension = Path.GetExtension(file.FileName);
                    string path;

                    using (var tmp = new TempFile())
                    {
                        path = tmp.Path;
                        Logger.Debug("-- Upload File --:Is File Exists/" + System.IO.File.Exists(path));
                    }

                    // store the file inside ~/App_Data/uploads folder
                    //var path = Path.Combine(Server.MapPath("~/App_Data/uploads"), fileName);
                    file.SaveAs(path);

                    attach.Filename      = fileName;
                    attach.ContentType   = file.ContentType;
                    attach.TempPath      = path;
                    attach.FileExtension = fileExtension;
                    attach.FileSize      = file.ContentLength;

                    if (attachVM.ListIndex == null)
                    {
                        attachVM.AttachmentList.Add(attach);
                    }
                }

                return(Json(new
                {
                    Valid = true,
                    Data = attachVM.AttachmentList
                }, "text/html"));
            }

Outer:
            return(Json(new
            {
                Valid = false,
                Error = string.Empty,
                Errors = GetModelValidationErrors()
            }, "text/html"));
        }
Example #7
0
        public ActionResult Edit(AttachViewModel attachVM)
        {
            Logger.Info(_logMsg.Clear().SetPrefixMsg("Edit Attachment").Add("DocName", attachVM.DocName)
                        .Add("DocDesc", attachVM.DocDesc).ToInputLogString());

            try
            {
                if (attachVM.AttachmentId.HasValue && attachVM.AttachmentId != 0)
                {
                    ModelState.Remove("FileAttach");
                }

                if (string.IsNullOrEmpty(attachVM.ExpiryDate))
                {
                    ModelState.AddModelError("ExpiryDate", string.Format(CultureInfo.InvariantCulture, Resource.ValErr_RequiredField, Resource.Lbl_ExpiryDate));
                }
                else
                {
                    if (attachVM.ExpiryDate.ParseDateTime(Constants.DateTimeFormat.DefaultShortDate) < DateTime.Now.Date)
                    {
                        ModelState.AddModelError("ExpiryDate", Resource.ValErr_InvalidDate_MustMoreThanToday);
                    }
                }

                //if (attachVM.Status.HasValue == false)
                //{
                //    ModelState.AddModelError("Status", string.Format(CultureInfo.InvariantCulture, Resource.ValErr_RequiredField, Resource.Lbl_Status_Thai));
                //}

                // Validate MaxLength
                if (attachVM.DocDesc != null && attachVM.DocDesc.Count() > Constants.MaxLength.AttachDesc)
                {
                    ModelState.AddModelError("DocDesc", string.Format(CultureInfo.InvariantCulture, Resource.ValErr_StringLength, Resource.Lbl_Detail, Constants.MaxLength.AttachDesc));
                    goto Outer;
                }

                if (ModelState.IsValid)
                {
                    AttachmentEntity attach = new AttachmentEntity();

                    var file = attachVM.FileAttach;
                    attach.Name         = attachVM.DocName;
                    attach.Description  = attachVM.DocDesc;
                    attach.ExpiryDate   = attachVM.ExpiryDate.ParseDateTime(Constants.DateTimeFormat.DefaultShortDate);
                    attach.CustomerId   = attachVM.CustomerId;
                    attach.AttachmentId = attachVM.AttachmentId.HasValue ? attachVM.AttachmentId.Value : 0;
                    attach.Status       = Constants.ApplicationStatus.Active;

                    #region "AttachType"

                    var selectedAttachType = attachVM.DocTypeCheckBoxes.Where(x => x.Checked == true)
                                             .Select(x => new AttachmentTypeEntity
                    {
                        DocTypeId    = x.Value.ToNullable <int>(),
                        CreateUserId = this.UserInfo.UserId
                    }).ToList();

                    if (attachVM.AttachTypeList != null && attachVM.AttachTypeList.Count > 0)
                    {
                        var prevAttachTypes = (from at in attachVM.AttachTypeList
                                               select new AttachmentTypeEntity
                        {
                            AttachmentId = at.AttachmentId,
                            Code = at.Code,
                            Name = at.Name,
                            DocTypeId = at.DocTypeId,
                            IsDelete = !selectedAttachType.Select(x => x.DocTypeId).Contains(at.DocTypeId),
                            Status = at.Status,
                            CreateUserId = this.UserInfo.UserId
                        }).ToList();

                        var dupeAttachTypes = new List <AttachmentTypeEntity>(selectedAttachType);
                        dupeAttachTypes.AddRange(prevAttachTypes);

                        var duplicates = dupeAttachTypes.GroupBy(x => new { x.DocTypeId })
                                         .Where(g => g.Count() > 1)
                                         .Select(g => (object)g.Key.DocTypeId);

                        if (duplicates.Any())
                        {
                            //Logger.Info(_logMsg.Clear().SetPrefixMsg("Duplicate ID in list")
                            //    .Add("IDs", StringHelpers.ConvertListToString(duplicates.ToList(), ",")).ToInputLogString());
                            prevAttachTypes.RemoveAll(x => duplicates.Contains(x.DocTypeId));
                        }

                        selectedAttachType.AddRange(prevAttachTypes);
                    }

                    attach.AttachTypeList = selectedAttachType;

                    #endregion

                    // Verify that the user selected a file
                    if (file != null && file.ContentLength > 0)
                    {
                        _commonFacade = new CommonFacade();
                        ParameterEntity paramSingleFileSize = _commonFacade.GetCacheParamByName(Constants.ParameterName.SingleFileSize);
                        int?            limitSingleFileSize = paramSingleFileSize.ParamValue.ToNullable <int>();

                        if (file.ContentLength > limitSingleFileSize.Value)
                        {
                            ModelState.AddModelError("FileAttach", string.Format(CultureInfo.InvariantCulture, Resource.ValError_SingleFileSizeExceedMaxLimit, (limitSingleFileSize.Value / 1048576)));
                            goto Outer;
                        }

                        // extract only the filename
                        var fileName = Path.GetFileName(file.FileName);


                        ParameterEntity param = _commonFacade.GetCacheParamByName(Constants.ParameterName.RegexFileExt);
                        Match           match = Regex.Match(fileName, param.ParamValue, RegexOptions.IgnoreCase);

                        if (!match.Success)
                        {
                            ModelState.AddModelError("FileAttach", Resource.ValError_FileExtension);
                            goto Outer;
                        }

                        var docFolder   = _commonFacade.GetCSMDocumentFolder();
                        int seqNo       = _commonFacade.GetNextAttachmentSeq();
                        var fileNameUrl = ApplicationHelpers.GenerateFileName(docFolder, Path.GetExtension(file.FileName), seqNo, Constants.AttachmentPrefix.Customer);

                        var targetFile = string.Format(CultureInfo.InvariantCulture, "{0}\\{1}", docFolder, fileNameUrl);
                        file.SaveAs(targetFile);

                        attach.Url         = fileNameUrl;
                        attach.Filename    = fileName;
                        attach.ContentType = file.ContentType;
                    }

                    attach.CreateUserId = this.UserInfo.UserId; // for add CustomerLog

                    _customerFacade = new CustomerFacade();
                    _customerFacade.SaveCustomerAttachment(attach);

                    return(Json(new
                    {
                        Valid = true
                    }, "text/html"));
                }

Outer:
                return(Json(new
                {
                    Valid = false,
                    Error = string.Empty,
                    Errors = GetModelValidationErrors()
                }, "text/html"));
            }
            catch (Exception ex)
            {
                Logger.Error("Exception occur:\n", ex);
                Logger.Info(_logMsg.Clear().SetPrefixMsg("Edit Attachment").Add("Error Message", ex.Message).ToFailLogString());
                return(Json(new
                {
                    Valid = false,
                    Error = Resource.Error_System,
                    Errors = string.Empty
                }, "text/html"));
            }
        }
Example #8
0
        public ActionResult InitEdit(int?attachmentId, int?customerId, string documentLevel)
        {
            Logger.Info(_logMsg.Clear().SetPrefixMsg("InitEdit Attachment").Add("AttachmentId", attachmentId)
                        .Add("CustomerId", customerId).Add("DocumentLevel", documentLevel).ToInputLogString());

            try
            {
                _commonFacade   = new CommonFacade();
                _customerFacade = new CustomerFacade();

                #region "For show in hint"

                ParameterEntity param = _commonFacade.GetCacheParamByName(Constants.ParameterName.RegexFileExt);
                ParameterEntity paramSingleFileSize = _commonFacade.GetCacheParamByName(Constants.ParameterName.SingleFileSize);

                int?limitSingleFileSize = paramSingleFileSize.ParamValue.ToNullable <int>();
                var singleLimitSize     = limitSingleFileSize.HasValue ? (limitSingleFileSize / 1048576) : 0;
                ViewBag.UploadLimitType = string.Format(CultureInfo.InvariantCulture, param.ParamDesc, singleLimitSize);

                #endregion

                var attachVM = new AttachViewModel();
                List <DocumentTypeEntity> docTypeList = null;

                if (attachmentId.HasValue)
                {
                    AttachmentEntity selectedAttach = _customerFacade.GetAttachmentByID(attachmentId.Value, documentLevel);
                    attachVM.Filename   = selectedAttach.Filename;
                    attachVM.DocName    = selectedAttach.Name;
                    attachVM.DocDesc    = selectedAttach.Description;
                    attachVM.ExpiryDate = selectedAttach.ExpiryDateDisplay;
                    attachVM.CustomerId = selectedAttach.CustomerId;
                    attachVM.Status     = selectedAttach.Status;

                    attachVM.AttachmentId = attachmentId.Value;

                    docTypeList = _commonFacade.GetDocumentTypeList(selectedAttach.AttachTypeList, Constants.DocumentCategory.Customer);
                }
                else
                {
                    attachVM.CustomerId = customerId; // case new
                    docTypeList         = _commonFacade.GetActiveDocumentTypes(Constants.DocumentCategory.Customer);
                }

                if (docTypeList != null)
                {
                    attachVM.JsonAttachType    = JsonConvert.SerializeObject(docTypeList);
                    attachVM.DocTypeCheckBoxes = docTypeList.Select(x => new CheckBoxes
                    {
                        Value   = x.DocTypeId.ToString(),
                        Text    = x.Name,
                        Checked = x.IsChecked
                    }).ToList();
                }

                //var statusList = _commonFacade.GetStatusSelectList();
                //attachVM.StatusList = new SelectList((IEnumerable)statusList, "Key", "Value", string.Empty);

                return(PartialView("~/Views/Document/_EditAttachment.cshtml", attachVM));
            }
            catch (Exception ex)
            {
                Logger.Error("Exception occur:\n", ex);
                Logger.Info(_logMsg.Clear().SetPrefixMsg("InitEdit Attachment").Add("Error Message", ex.Message).ToFailLogString());
                return(Error(new HandleErrorInfo(ex, this.ControllerContext.RouteData.Values["controller"].ToString(),
                                                 this.ControllerContext.RouteData.Values["action"].ToString())));
            }
        }