public IActionResult EditAuthor(EditAuthorViewModel model) { if (ModelState.IsValid) { if (model == null) { throw new Exception(); } AuthorDTO newAuthor = new AuthorDTO { Id = model.Id, Name = model.Name.Trim(), Description = model.Description, Surname = model.Surname.Trim() }; if (model.Image != null) { byte[] imageData = null; using (var binaryReader = new BinaryReader(model.Image.OpenReadStream())) { imageData = binaryReader.ReadBytes((int)model.Image.Length); } newAuthor.Image = imageData; } else { throw new Exception(); } _authorService.Update(newAuthor); } return(RedirectToAction("AuthorsList")); }
public ActionResult Edit(EditAuthorViewModel vm) { Author author = _context.Authors.Where(x => x.Id == vm.Id).FirstOrDefault(); if (author == null) { return(RedirectToAction("Index", "Error")); } if (!ModelState.IsValid) { return(View(vm)); } if (vm.Image != null) { //remove old image var fullPath = Server.MapPath("~/Content/Uploads/" + author.Image); System.IO.File.Delete(fullPath); // upload new one string[] allowedExtensions = new string[] { ".jpg", ".png", ".jpeg" }; string pic = Guid.NewGuid().ToString() + Path.GetFileName(vm.Image.FileName); bool find = false; foreach (string extension in allowedExtensions) { if (pic.Contains(extension)) { find = true; break; } } if (!find) { ModelState.AddModelError("Errors", "არასწორი ფორმატი"); return(View(vm)); } string path = Path.Combine(Server.MapPath("~/Content/Uploads/"), pic); // file is uploaded vm.Image.SaveAs(path); vm.FileName = pic; author.Image = pic; } author.FirstName = vm.FirstName; author.LastName = vm.LastName; author.Email = vm.Email; author.GithubLink = vm.GithubLink; author.LinkedinLink = vm.LinkedinLink; author.DribbleLink = vm.DribbleLink; author.BehanceLink = vm.BehanceLink; _context.SaveChanges(); return(RedirectToAction("Index", "Author")); }
public IHttpActionResult Update(EditAuthorViewModel model) { var author = _authorRepository.GetById(model.Id); _mapper.Map(model, author); _authorRepository.Update(author); return(Ok(author)); }
// Updates the Author that the user has selected and saves the changes in the DB public void EditAuthor(EditAuthorViewModel viewModel) { using (var context = this.CreateContext()) { context.Authors.Attach(viewModel.Author); viewModel.Author.FirstName = viewModel.FirstName; viewModel.Author.LastName = viewModel.LastName; viewModel.Author.BirthDate = viewModel.Birthday; context.SaveChanges(); } }
//getting author public async Task <EditAuthorViewModel> GetAuthor(int id) { var author = await _db.Authors.Include(y => y.BooksAuthors).ThenInclude(z => z.Book) .SingleOrDefaultAsync(x => x.Id == id); var editingAuthor = new EditAuthorViewModel() { Id = author.Id, FullName = author.FullName, Dob = author.Dob, Books = author.BooksAuthors.Select(ba => new BookListViewModel(ba.Book.Id, ba.Book.Title)) }; return(editingAuthor); }
public ActionResult Edit(EditAuthorViewModel editAuthor) { if (ModelState.IsValid) { int result = _authorProvider.EditAuthor(editAuthor); if (result == 0) { ModelState.AddModelError("", "Помилка збереження даних"); } else if (result != 0) { return(RedirectToAction("Index")); } } return(View(editAuthor)); }
public IActionResult EditAuthor(string id) { AuthorDTO getedAuthor = _authorService.Get(id); if (getedAuthor == null) { return(RedirectToAction("Error")); } EditAuthorViewModel model = new EditAuthorViewModel { Name = getedAuthor.Name.Trim(), Surname = getedAuthor.Surname.Trim(), Description = getedAuthor.Description }; return(View(model)); }
public EditAuthorViewModel EditAuthor(int id) { EditAuthorViewModel model = null; var author = _authorRepository.GetAuthorById(id); if (author != null) { model = new EditAuthorViewModel { Id = author.Id, FirstName = author.FirstName, LastName = author.LastName }; } return(model); }
public ActionResult EditAuthor(EditAuthorViewModel post) { StoredProcs.Authors_CreateOrUpdateAuthor( post.Author.Slug, post.Author.Name, post.Author.IsAdmin, post.Author.DescriptionHtml, post.Author.ShortDescription, Inedo.InedoLib.Util.NullIf(post.Author.ImageUrl, string.Empty) ).Execute(); if (!string.IsNullOrEmpty(post.Password)) { StoredProcs.Authors_SetPassword(post.Author.Slug, post.Password).Execute(); } return(RedirectToAction("index")); }
public ActionResult EditAuthor(EditAuthorViewModel post) { DB.Authors_CreateOrUpdateAuthor( post.Author.Slug, post.Author.Name, post.Author.IsAdmin, post.Author.DescriptionHtml, post.Author.ShortDescription, Inedo.AH.NullIf(post.Author.ImageUrl, string.Empty), post.Author.IsActive ); if (!string.IsNullOrEmpty(post.Password)) { DB.Authors_SetPassword(post.Author.Slug, post.Password); } return(RedirectToRoute("LoginListAdmin")); }
public ActionResult EditAuthor(int id) { var model = new EditAuthorViewModel(); try { using (var dbContext = new Bookshop_DBContext()) { model.Author = dbContext.Authors.First(a => a.author_id == id).Clone(); } } catch (SqlException e) { Console.WriteLine(e); throw; } return(View(model)); }
public int EditAuthor(EditAuthorViewModel editAuthor) { try { var author = _authorRepository.GetAuthorById(editAuthor.Id); if (author != null) { author.FirstName = editAuthor.FirstName; author.LastName = editAuthor.LastName; _authorRepository.SaveChange(); } } catch { return(0); } return(editAuthor.Id); }
public async Task <ActionResult> Edit(EditAuthorViewModel model) { if (ModelState.IsValid) { Author author = await db.Authours.FindAsync(model.Id); author.FirstName = model.FirstName; author.LastName = model.LastName; author.Email = model.Email; author.Address = model.Address; author.PhoneNumber = model.PhoneNumber; author.LastUpdate = DateTime.Now; db.Entry(author).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(model)); }
public async Task <IHttpActionResult> Put(EditAuthorViewModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } using (var ctx = new NewsDbContext()) { var author = new Author() { Id = model.Id.Value, Name = model.Name }; ctx.Authors.Attach(author); ctx.Entry(author).State = EntityState.Modified; await ctx.SaveChangesAsync(); return(StatusCode(HttpStatusCode.NoContent)); } }
public ActionResult Edit(int Id) { Author author = _context.Authors.Where(x => x.Id == Id).FirstOrDefault(); if (author == null) { return(RedirectToAction("Index", "Error")); } EditAuthorViewModel vm = new EditAuthorViewModel { Id = author.Id, FirstName = author.FirstName, LastName = author.LastName, FileName = author.Image, Email = author.Email, GithubLink = author.GithubLink, LinkedinLink = author.LinkedinLink, BehanceLink = author.BehanceLink, DribbleLink = author.DribbleLink }; return(View(vm)); }
public async Task <IActionResult> Edit(EditAuthorViewModel viewModel) { await this.authorsService.EditAsync(viewModel.Id, viewModel.FirstName, viewModel.MiddleName, viewModel.LastName); return(this.RedirectToAction("Index")); }
public async Task OnGetAsync(Guid id) { var authorDto = await _authorAppService.GetAsync(id); Author = ObjectMapper.Map <AuthorDto, EditAuthorViewModel>(authorDto); }
public EditAuthorPage(Author author) { this.InitializeComponent(); this.viewModel = new EditAuthorViewModel(author); this.DataContext = this.viewModel; }