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)); }
public ActionResult AddExpos() { var exposViewModel = new ExposViewModel { Title = "Создание новой выставки", AddButtonTitle = "Создать", RedirectUrl = Url.Action("Index", "Expos") }; return(View(exposViewModel)); }
public async Task <ActionResult> EditExpo(int Id) { var exposViewModel = new ExposViewModel(); switch (Properties.Settings.Default.GetDataFrom) { case "db": var expo = await expoService.GetExpoAsync(Id); exposViewModel = new ExposViewModel { Title = "Изменение выставки", AddButtonTitle = "Сохранить", RedirectUrl = Url.Action("Index", "Expos"), ExpoName = expo.expoName, DateStart = expo.startDate, DateEnd = expo.endDate, Description = expo.description }; break; case "Json": var expo2 = await expoService.GetExpoFromJsonAsync(Id); exposViewModel = new ExposViewModel { Title = "Изменение выставки", AddButtonTitle = "Сохранить", RedirectUrl = Url.Action("DetailsOfExpo", "Expos", new { _idExpo = Id }), ExpoName = expo2.expoName, DateStart = expo2.startDate, DateEnd = expo2.endDate, Description = expo2.description }; break; } return(View(exposViewModel)); }