Esempio n. 1
0
        public JsonResult CreateResultArchive(string fileName, long fileSize)
        {
            var file = new File
            {
                Path       = fileName,
                Type       = FileType.Compressed,
                FileSize   = fileSize,
                UploadedBy = new OrganizationRoleUser(_session.UserSession.CurrentOrganizationRole.OrganizationRoleUserId),
                UploadedOn = DateTime.Now
            };

            file = _fileRepository.Save(file);

            var rapsUpload = new RapsUpload
            {
                FileId     = file.Id,
                UploadTime = DateTime.Now,
                StatusId   = (long)RapsUploadStatus.UploadStarted,
                UploadedBy = _session.UserSession.CurrentOrganizationRole.OrganizationRoleUserId
            };

            rapsUpload = _rapsUploadRepository.Save(rapsUpload);

            //update the file name
            file.Path = _fileHelper.AddPostFixToFileName(file.Path, rapsUpload.Id.ToString());
            _fileRepository.Save(file);


            var editModel = new RapsFileUploadEditModel
            {
                File = file,
                Id   = rapsUpload.Id
            };

            return(Json(editModel, JsonRequestBehavior.AllowGet));
        }
        public JsonResult CreateResultArchive(long eventId, string fileName, long fileSize)
        {
            if (eventId < 1)
            {
                throw new Exception("EventId should not be empty!");
            }
            try
            {
                var theEvent = _eventRepository.GetById(eventId);
                if (theEvent == null || theEvent.EventDate.Date > DateTime.Now.Date || theEvent.Status != EventStatus.Active || theEvent.PodIds.IsNullOrEmpty())
                {
                    throw new Exception("Provide a valid EventId!");
                }
            }
            catch
            {
                var model = new ResultArchiveUploadEditModel
                {
                    EventId = -1,
                    File    = null,
                    Id      = 0
                };

                return(Json(model, JsonRequestBehavior.AllowGet));
            }

            var file = new File
            {
                Path       = fileName,
                Type       = FileType.Compressed,
                FileSize   = fileSize,
                UploadedBy = new OrganizationRoleUser(_session.UserSession.CurrentOrganizationRole.OrganizationRoleUserId),
                UploadedOn = DateTime.Now
            };

            file = _fileRepository.Save(file);

            var resultArchive = new ResultArchive
            {
                FileId                  = file.Id,
                EventId                 = eventId,
                UploadStartTime         = DateTime.Now,
                Status                  = ResultArchiveUploadStatus.Uploading,
                UploadedByOrgRoleUserId =
                    _session.UserSession.CurrentOrganizationRole.OrganizationRoleUserId
            };

            resultArchive = _resultArchiveUploadRepository.Save(resultArchive);

            //update the file name
            file.Path = _fileHelper.AddPostFixToFileName(file.Path, resultArchive.Id.ToString());
            _fileRepository.Save(file);


            //return ResultArchiveUploadEditModel;
            var editModel = new ResultArchiveUploadEditModel
            {
                EventId = eventId,
                File    = file,
                Id      = resultArchive.Id
            };

            return(Json(editModel, JsonRequestBehavior.AllowGet));
        }