Пример #1
0
        /// <summary>
        /// Lấy về rep tương ứng
        /// </summary>
        /// <param name="data">Dữ liều</param>
        /// <returns>Lấy về Rep</returns>
        /// Create by: dvthang:10.03.2018
        private IBaseReportRepository GetRep(BaseParam data)
        {
            IBaseReportRepository rep = null;

            switch (data.ReportID)
            {
                //case MT.Library.Enummation.ReportID.ChamCong:
                //    rep = (LabordayRepository)this.unitOfWork.GetRepByName("Laborday");
                //    break;
                //case MT.Library.Enummation.ReportID.ChamCongTC:
                //    rep = (LabordayRepository)this.unitOfWork.GetRepByName("Laborday");
                //    break;
                //case MT.Library.Enummation.ReportID.LuongCoBan:
                //    rep = (SalaryExportRepository)this.unitOfWork.GetRepByName("SalaryExport");
                //    break;
                //case MT.Library.Enummation.ReportID.HeSoTienCong:
                //    rep = (WageCoefficientExportRepository)this.unitOfWork.GetRepByName("WageCoefficientExport");
                //    break;
                //case MT.Library.Enummation.ReportID.ThueKhoanChuyenMon:
                //    rep = (ContractedProfessionalExportRepository)this.unitOfWork.GetRepByName("ContractedProfessionalExport");
                //    break;
                //case MT.Library.Enummation.ReportID.ThueKhoanChuyenMonExcel:
                //    rep = (ContractedProfessionalExportExcelRepository)this.unitOfWork.GetRepByName("ContractedProfessionalExportExcel");
                //    break;
                //case MT.Library.Enummation.ReportID.BaoCaoSoNgayConDeChamCong:
                //    rep = (DaysLeftExportExcelRepository)this.unitOfWork.GetRepByName("DaysLeftExportExcel");
                //break;
            }
            return(rep);
        }
Пример #2
0
        public Task <HttpResponseMessage> Get(string data)
        {
            try
            {
                if (!string.IsNullOrEmpty(data))
                {
                    BaseParam param  = CommonFunction.DeserializeObject <BaseParam>(data);
                    Token     oToken = null;
                    if (tokenRep.ValidateToken(param.TokenID, ref oToken))
                    {
                        HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);

                        IBaseReportRepository rep = this.GetRep(param);

                        byte[] xlsInBytes = rep.ExportExcel(param);

                        result.Content = new ByteArrayContent(xlsInBytes);
                        result.Content.Headers.ContentType                 = new MediaTypeHeaderValue("application/octet-stream");
                        result.Content.Headers.ContentDisposition          = new ContentDispositionHeaderValue("attachment");
                        result.Content.Headers.ContentDisposition.FileName = $"{Guid.NewGuid()}.xls";
                        result.Content.Headers.ContentLength               = xlsInBytes.Length;
                        return(Task.FromResult(result));
                    }
                    else
                    {
                        return(Task.FromResult(new HttpResponseMessage(HttpStatusCode.Unauthorized)));
                    }
                }
            }
            catch (Exception ex)
            {
                CommonFunction.CommonLogError(ex);
            }
            return(Task.FromResult(new HttpResponseMessage(HttpStatusCode.InternalServerError)));
        }