public ActionResult Upload_SecondStepReconciliationPack(FormCollection form)
        {
            string filename = string.Empty;
            string path     = string.Empty;

            try
            {
                filename = string.Format("{0}_{1}_{2}.zip", DateTime.Now.ToString("dd_MM_yyyy_hh_mm"), CurrentUser.Login, Guid.NewGuid().ToString());
                path     = Path.Combine(ConfiguraionProvider.FileStorageFolder, filename);
                if (Request.Files == null || Request.Files.Count < 1)
                {
                    return(PartialView("_ErrorMessage", "Выберите zip-архив c dbf-файлом для загрузки"));
                }
                HttpPostedFileBase upload = Request.Files[0];
                upload.SaveAs(path);
                List <FundResponse.UploadReportData> report = fundRequestBusinessLogic.Upload_SecondStepReconciliationPack(CurrentUser, path);

                //сохранение истории файлов
                List <FundFileHistory> listHistory = new List <FundFileHistory>();
                FundFileHistory        template    = new FundFileHistory()
                {
                    StatusID = FundFileHistoryStatus.SverkaResponse.Id,
                    Date     = DateTime.Now,
                    UserID   = CurrentUser.Id,
                    FileName = Request.Files[0].FileName,                       //оригинальное название файла
                    FileUrl  = Path.Combine(Constants.SverkaResponse, filename) //имя, как мы его сохраняем
                };
                var groupByClientVisitId = report.GroupBy(a => a.ClientVisitId).Select(b => b.First()).ToList();
                listHistory = groupByClientVisitId.Where(a => (a.ClientVisitId != 0 && a.VisitGroupId != 0 && a.ClientId != 0))
                              .Select(item => new FundFileHistory(item, template)).ToList();
                if (listHistory.Count > 0)
                {
                    fundRequestBusinessLogic.FundFileHistory_Save(listHistory);
                    upload.SaveAs(Path.Combine(ConfiguraionProvider.FileStorageFolder, Constants.SverkaResponse, filename));
                }

                return(PartialView("_FundResponseUploadReport", report.Select(item => Mapper.Map <FundResponseUploadReportModel>(item))));
            }
            catch (Exception ex)
            {
                return(PartialView("_ErrorMessage", ex.Message));
            }
            finally
            {
                if (!string.IsNullOrEmpty(path) && System.IO.File.Exists(path))
                {
                    System.IO.File.Delete(path);
                }
            }
        }
示例#2
0
 public FundFileHistoryModel(FundFileHistory item, List <User> listUser, List <ReferenceItem> listStatus)
 {
     StatusID    = item.StatusID;
     Status      = listStatus.Where(a => a.Id == item.StatusID).Select(b => b.Name).FirstOrDefault();
     Date        = item.Date;
     UserID      = item.UserID;
     UserName    = listUser.Where(a => a.Id == item.UserID).FirstOrDefault().Fullname;
     FileName    = item.FileName;
     FileUrl     = item.FileUrl;
     IsExistFile = System.IO.File.Exists(Path.Combine(ConfiguraionProvider.FileStorageFolder, item.FileUrl));
     if (IsExistFile)
     {
         Size = GetFileSizeToString((float)new System.IO.FileInfo(Path.Combine(ConfiguraionProvider.FileStorageFolder, item.FileUrl)).Length);
     }
 }