public IActionResult Put(int id, [FromForm] NotebookViewModel notebookViewModel) { if (ModelState.IsValid) { var currentUser = User.Claims.Single(c => c.Type == ClaimTypes.Email).Value; if (!_notebookService.CanUserEdit(id, currentUser)) { return(Forbid()); } var notebook = _context.Notebook.SingleOrDefault(b => b.Id == id); if (notebook == null) { return(NotFound()); } else { if (notebookViewModel.ImageFile != null) { if (notebook.Image != null) { // Delete the old image file var oldFilePath = _hostingEnvironment.WebRootPath + notebook.Image; System.IO.File.Delete(oldFilePath); } var fileName = Guid.NewGuid() + notebookViewModel.ImageFile.FileName; var imageFilesFolderPath = Path.Combine(_hostingEnvironment.WebRootPath, "Images"); var filePath = Path.Combine(imageFilesFolderPath, fileName); using (var fileStream = new FileStream(filePath, FileMode.Create)) { notebookViewModel.ImageFile.CopyTo(fileStream); } notebook.Image = Path.Combine("/Images/", fileName); notebook.ImageName = notebookViewModel.ImageFile.FileName; } notebook.Name = notebookViewModel.Name; notebook.Public = notebookViewModel.Public; _context.SaveChanges(); return(Ok(notebook)); } } else { return(BadRequest(ModelState)); } }
//private void ProcessDrop(object sender, ProcessDropEventArgs<IMainMenuItem> e) //{ // Log.Debug(e.DataItem.ToJson()); // /* // if (e.OldIndex > -1) // { // ContextNote.ToDos.Move(e.OldIndex, e.NewIndex); // e.ItemsSource.Move(e.OldIndex, e.NewIndex); // } // else // { // ContextNote.ToDos.Insert(e.NewIndex, e.DataItem.ToDoItem); // e.ItemsSource.Insert(e.NewIndex, e.DataItem); // } // ContextNote.Save(); // */ //} private void NotebookMenu_OnDataContextChanged(object sender, DependencyPropertyChangedEventArgs e) { _model = DataContext as NotebookMenuViewModel; if (_model == null || _model.Notebooks == null) { return; } NotebookViewModel first = _model?.Notebooks.FirstOrDefault(); if (first != null) { _model.SelectedItemChangedCommand?.Execute(first); } }
private NotebookViewModel MapNotebookEntityToNotebookViewModel(NotebookEntity entity, Guid?selectedPage = null) { var pages = new List <PageViewModel>(); if (entity.Pages != null && entity.Pages.Count() > 0) { foreach (var pageEntity in entity.Pages) { pages.Add(MapPageEntityToPageViewModel(pageEntity)); } } var vm = new NotebookViewModel { Id = entity.Id, Name = entity.Name, Pages = pages, SelectedPage = selectedPage ?? pages.FirstOrDefault()?.Id }; return(vm); }
public IActionResult Post([FromForm] NotebookViewModel notebookViewModel) { if (ModelState.IsValid) { var notebook = new Notebook(); if (notebookViewModel.ImageFile != null) { var fileName = Guid.NewGuid() + notebookViewModel.ImageFile.FileName; var imageFilesFolderPath = Path.Combine(_hostingEnvironment.WebRootPath, "Images"); var filePath = Path.Combine(imageFilesFolderPath, fileName); using (var fileStream = new FileStream(filePath, FileMode.Create)) { notebookViewModel.ImageFile.CopyTo(fileStream); } notebook.Image = Path.Combine("/Images/", fileName); notebook.ImageName = notebookViewModel.ImageFile.FileName; } var currentUser = User.Claims.Single(c => c.Type == ClaimTypes.Email).Value; notebook.Name = notebookViewModel.Name; notebook.Public = notebookViewModel.Public; notebook.User = currentUser; _context.Notebook.Add(notebook); _context.SaveChanges(); return(Ok()); } else { return(BadRequest(ModelState)); } }
public async Task <ActionResult> NotebookKayit(NotebookViewModel model) { var adminId = HttpContext.User.Identity.GetUserId(); try { #region NotebookKayitResim1 if (model.PostedFileNotebookResim1 != null && model.PostedFileNotebookResim1.ContentLength > 0) { var file = model.PostedFileNotebookResim1; string fileName = Path.GetFileNameWithoutExtension(file.FileName); string extName = Path.GetExtension(file.FileName); fileName = StringHelper.UrlFormatConverter(fileName); fileName += StringHelper.GetCode(); var klasoryolu = Server.MapPath("~/Notebook/"); var dosyayolu = Server.MapPath("~/Notebook/") + fileName + extName; if (!Directory.Exists(klasoryolu)) { Directory.CreateDirectory(klasoryolu); } file.SaveAs(dosyayolu); WebImage img = new WebImage(dosyayolu); img.Resize(250, 250, false); img.AddTextWatermark("HepsiBuradaDb"); img.Save(dosyayolu); var oldPath = model.NotebookResim1; model.NotebookResim1 = "/Notebook/" + fileName + extName; System.IO.File.Delete(Server.MapPath(oldPath)); } #endregion #region NotebookKayitResim2 if (model.PostedFileNotebookResim2 != null && model.PostedFileNotebookResim2.ContentLength > 0) { var file = model.PostedFileNotebookResim2; string fileName = Path.GetFileNameWithoutExtension(file.FileName); string extName = Path.GetExtension(file.FileName); fileName = StringHelper.UrlFormatConverter(fileName); fileName += StringHelper.GetCode(); var klasoryolu = Server.MapPath("~/Notebook/"); var dosyayolu = Server.MapPath("~/Notebook/") + fileName + extName; if (!Directory.Exists(klasoryolu)) { Directory.CreateDirectory(klasoryolu); } file.SaveAs(dosyayolu); WebImage img = new WebImage(dosyayolu); img.Resize(250, 250, false); img.AddTextWatermark("HepsiBuradaDb"); img.Save(dosyayolu); var oldPath = model.NotebookResim2; model.NotebookResim2 = "/Notebook/" + fileName + extName; System.IO.File.Delete(Server.MapPath(oldPath)); } #endregion #region NotebookKayitResim3 if (model.PostedFileNotebookResim3 != null && model.PostedFileNotebookResim3.ContentLength > 0) { var file = model.PostedFileNotebookResim3; string fileName = Path.GetFileNameWithoutExtension(file.FileName); string extName = Path.GetExtension(file.FileName); fileName = StringHelper.UrlFormatConverter(fileName); fileName += StringHelper.GetCode(); var klasoryolu = Server.MapPath("~/Notebook/"); var dosyayolu = Server.MapPath("~/Notebook/") + fileName + extName; if (!Directory.Exists(klasoryolu)) { Directory.CreateDirectory(klasoryolu); } file.SaveAs(dosyayolu); WebImage img = new WebImage(dosyayolu); img.Resize(250, 250, false); img.AddTextWatermark("HepsiBuradaDb"); img.Save(dosyayolu); var oldPath = model.NotebookResim3; model.NotebookResim3 = "/Notebook/" + fileName + extName; System.IO.File.Delete(Server.MapPath(oldPath)); } #endregion var data = new Notebook { AdminID = adminId, NotebookMarka = model.NotebookMarka, EklenmeTarihi = model.EklenmeTarihi, NotebookEkranKartiHafiza = model.NotebookEkranKartiHafiza, NotebookAgirlik = model.NotebookAgirlik, NotebookEkranKartiMarka = model.NotebookEkranKartiMarka, NotebookFiyat = model.NotebookFiyat, NotebookGarantiSuresi = model.NotebookGarantiSuresi, NotebookHarddisk = model.NotebookHarddisk, NotebookIslemci = model.NotebookIslemci, NotebookIsletimSistemi = model.NotebookIsletimSistemi, NotebookRam = model.NotebookRam, NotebookKlavye = model.NotebookKlavye, NotebookRamTipi = model.NotebookRamTipi, Elektronik = model.Elektronik, NotebookID = model.NotebookID, NotebookStok = model.NotebookStok, NotebookResim1 = model.NotebookResim1, NotebookResim2 = model.NotebookResim2, NotebookResim3 = model.NotebookResim3 }; new NotebookRepo().Insert(data); TempData["Message"] = $"{model.NotebookID} no'lu kayıt başarıyla eklenmiştir"; return(RedirectToAction("Index", "Bilgisayar")); } catch (DbEntityValidationException ex) { TempData["Model"] = new ErrorViewModel() { Text = $"Bir hata oluştu: {EntityHelper.ValidationMessage(ex)}", ActionName = "Index", ControllerName = "Bilgisayar", ErrorCode = 500 }; return(RedirectToAction("Error", "Home")); } catch (Exception ex) { TempData["Model"] = new ErrorViewModel() { Text = $"Bir hata oluştu: {ex.Message}", ActionName = "Index", ControllerName = "Bilgisayar", ErrorCode = 500 }; return(RedirectToAction("Error", "Home")); } }