Exemplo n.º 1
0
        public async Task <ActionResult> AddNewExpo(ExposViewModel _exposViewModel, string redirectUrl, HttpPostedFileBase uploadImage)
        {
            if (!ModelState.IsValid)
            {
                return(View(_exposViewModel));
            }
            var expo = new Expos
            {
                expoName    = _exposViewModel.ExpoName,
                startDate   = _exposViewModel.DateStart,
                endDate     = _exposViewModel.DateEnd,
                description = _exposViewModel.Description,
            };
            FileRepository fileRepository = new FileRepository();

            byte[] bytes;
            if (_exposViewModel.logoFile != null)
            {
                using (Stream inputStream = _exposViewModel.logoFile.InputStream)
                {
                    MemoryStream memoryStream = inputStream as MemoryStream;
                    if (memoryStream == null)
                    {
                        memoryStream = new MemoryStream();
                        inputStream.CopyTo(memoryStream);
                    }
                    bytes = memoryStream.ToArray();
                }
                //Byte[] bytes = _exposViewModel.logoFile.//System.IO.File.ReadAllBytes(expos.logoFile);
                String            fileBase64 = Convert.ToBase64String(bytes);
                FileFromJson.File file       = new FileFromJson.File()
                {
                    authorId = Convert.ToInt16(Session["UserId"]),
                    content  = fileBase64,
                    filename = _exposViewModel.logoFile.FileName,
                    fileType = "logo",
                    dateTime = DateTimeOffset.Now
                };
                file = await fileRepository.AddFileFromJsonAsync(file);

                expo.logoFileId = file.fileId;
            }
            switch (Properties.Settings.Default.GetDataFrom)
            {
            case "db":

                await expoService.AddExpoAsync(expo);

                break;

            case "Json":
                await expoService.AddExpoFromJsonAsync(expo);

                break;
            }
            return(RedirectToLocal(redirectUrl));
        }
Exemplo n.º 2
0
        public async Task <ActionResult> addFile(ExposFilesViewModel exposFilesViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(exposFilesViewModel));
            }
            var expoFile = new ExpoFilesFromJson.ExpoFiles()
            {
                expoId = exposFilesViewModel.expoId
            };
            FileRepository fileRepository = new FileRepository();

            byte[] bytes;
            if (exposFilesViewModel.file != null)
            {
                using (Stream inputStream = exposFilesViewModel.file.InputStream)
                {
                    MemoryStream memoryStream = inputStream as MemoryStream;
                    if (memoryStream == null)
                    {
                        memoryStream = new MemoryStream();
                        inputStream.CopyTo(memoryStream);
                    }
                    bytes = memoryStream.ToArray();
                }

                String            fileBase64 = Convert.ToBase64String(bytes);
                FileFromJson.File file       = new FileFromJson.File()
                {
                    authorId = Convert.ToInt16(Session["UserId"]),
                    content  = fileBase64,
                    filename = exposFilesViewModel.file.FileName,
                    fileType = "file",
                    dateTime = DateTimeOffset.Now
                };
                file = await fileRepository.AddFileFromJsonAsync(file);

                expoFile.fileId = file.fileId;
            }
            await expoFilesService.AddExpoFilesFromJsonAsync(expoFile, "expoFile");

            return(RedirectToLocal(exposFilesViewModel.RedirectUrl));
        }
Exemplo n.º 3
0
        public async Task <ActionResult> addFile(ImageViewModel imageViewModel)
        {
            FileRepository fileRepository = new FileRepository();

            byte[] bytes;
            if (imageViewModel.photoFile != null)
            {
                using (Stream inputStream = imageViewModel.photoFile.InputStream)
                {
                    MemoryStream memoryStream = inputStream as MemoryStream;
                    if (memoryStream == null)
                    {
                        memoryStream = new MemoryStream();
                        inputStream.CopyTo(memoryStream);
                    }
                    bytes = memoryStream.ToArray();
                }

                String            fileBase64 = Convert.ToBase64String(bytes);
                FileFromJson.File file       = new FileFromJson.File()
                {
                    authorId = Convert.ToInt16(Session["UserId"]),
                    content  = fileBase64,
                    filename = imageViewModel.photoFile.FileName,
                    fileType = "img",
                    dateTime = DateTimeOffset.Now
                };
                file = await fileRepository.AddFileFromJsonAsync(file);

                ExpoFilesFromJson.ExpoFiles expoFiles = new ExpoFilesFromJson.ExpoFiles()
                {
                    fileId = file.fileId,
                    expoId = imageViewModel.expoId
                };
                ExpoFilesRepository filesRepository = new ExpoFilesRepository();
                await filesRepository.AddExpoFilesFromJsonAsync(expoFiles, "photoExpo");
            }

            return(RedirectToLocal(imageViewModel.RedirectUrl));
        }