public void Update(BookEM entity) { using (var con = Connection) { con.Update(entity); } }
public void Update(BookEM entity) { using (IDbConnection db = new SqlConnection(connectionString)) { db.Query(SP_UPDATE_BOOK, entity, null, true, null, CommandType.StoredProcedure); } }
public void Update(BookVM entity) { using (var bookRepository = Context.Factory.GetService <IBookRepository>(Context.RootContext)) { BookEM model = this.Context.Mapper.MapTo <BookEM, BookVM>(entity); bookRepository.Update(model); } }
public long Create(BookEM entity) { using (var con = Connection) { var result = con.Insert(entity); var converted = (long)Convert.ChangeType(result, typeof(long)); return(converted); } }
public void AddBook(BookEM book) { using (SqlConnection db = new SqlConnection(connectionString)) { var authors = ToDataTableList(book.Authors, "AuthorID", typeof(int)); var spParams = new DynamicParameters(); spParams.Add("Authors", authors); spParams.AddDynamicParams(book); db.Execute("USP_InsertBook", spParams, commandType: CommandType.StoredProcedure); } }
public BookVM GetById(int id) { using (var bookRepository = Context.Factory.GetService <IBookRepository>(Context.RootContext)) using (var authorRepository = Context.Factory.GetService <IAuthorRepository>(Context.RootContext)) { BookEM entity = bookRepository.Get(id); IEnumerable <AuthorEM> authorsEm = authorRepository.GetByBook(id); IEnumerable <AuthorVM> authorsVm = Context.Mapper.MapTo <IEnumerable <AuthorVM>, IEnumerable <AuthorEM> >(authorsEm); BookVM retVal = Context.Mapper.MapTo <BookVM, BookEM>(entity); retVal.Authors = new List <AuthorVM>(authorsVm); return(retVal); } }
public bool UpdateBook(BookEM book) { using (SqlConnection db = new SqlConnection(connectionString)) { var authors = ToDataTableList(book.Authors, "AuthorID", typeof(int)); var spParams = new DynamicParameters(); spParams.Add("Authors", authors); spParams.AddDynamicParams(book); int rowsAffecred = db.Execute("USP_UpdateBook", spParams, commandType: CommandType.StoredProcedure); return(rowsAffecred != 0); } }
public ActionResult Edit([Bind(Include = "Id,Title,PublishDate,AuthorId")] BookEM bookEM) { if (ModelState.IsValid) { Book book = AutoMapper.Mapper.Map <BookEM, Book>(bookEM); _bookService.UpdateBook(book); _bookService.SaveChanges(); return(RedirectToAction("Index")); } List <Author> authors = _authorService.GetAllAuthor().ToList(); ViewBag.AuthorId = new SelectList(authors, "Id", "Name", bookEM.AuthorId); return(View(bookEM)); }
/// <summary> /// Edit a book View /// </summary> /// <param name="id"></param> /// <returns></returns> public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } int bookId = id ?? default(int); Book book = _bookService.GetBook(bookId); BookEM bookEM = AutoMapper.Mapper.Map <Book, BookEM>(book); if (book == null) { return(HttpNotFound()); } List <Author> authors = _authorService.GetAllAuthor().ToList(); ViewBag.AuthorId = new SelectList(authors, "Id", "Name", bookEM.AuthorId); return(View(bookEM)); }
public BookEM Create(BookEM entity) { throw new NotImplementedException(); }