public Int32 SavePublisherBooks(Publisher_BEL Publisher, IEnumerable <BooksDetails_BEL> Books) { int result = 0; using (TransactionScope scope = new TransactionScope()) { using (SqlConnection conn = new SqlConnection(conStr)) { try { conn.Open(); var BooksIds = GetPublisherBooksIds(Publisher.PublisherId, conn); var Groups = BooksIds.GroupBy(id => Books.Any(Book => Book.BookId == id)).ToList(); var RemoveGroup = Groups.ElementAt(0).Key ? (Groups.Count > 1 ? Groups.ElementAt(1).ToList() : new List <int>()) : Groups.ElementAt(0).ToList(); Books.ToList().ForEach(Book => InsertRemovePublisherBook(Publisher.PublisherId, Book.BookId, conn, PublishersBooksAction.INSERT)); RemoveGroup.ToList().ForEach(BookId => InsertRemovePublisherBook(Publisher.PublisherId, BookId, conn, PublishersBooksAction.REMOVE)); } catch (Exception ex) { } } scope.Complete(); } return(result > 0 ? result : 0); }
public Int32 SavePublishers(Publisher_BEL objBEL) { int PublisherID = 0; using (TransactionScope scope = new TransactionScope()) { using (SqlConnection conn = new SqlConnection(conStr)) { try { conn.Open(); using (SqlCommand cmd = new SqlCommand("InsertPublishers_SP", conn)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("PublisherName", objBEL.PublisherName); PublisherID = Convert.ToInt32(cmd.ExecuteScalar()); } } catch (Exception ex) { } } scope.Complete(); } return(PublisherID); }
public Int32 UpdatePublisherRecord(Publisher_BEL objBEL) { int result = 0; using (TransactionScope scope = new TransactionScope()) { using (SqlConnection conn = new SqlConnection(conStr)) { try { conn.Open(); using (SqlCommand cmd = new SqlCommand("UpdatePublishers_SP", conn)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("PublisherId", objBEL.PublisherId); cmd.Parameters.AddWithValue("PublisherName", objBEL.PublisherName); result = cmd.ExecuteNonQuery(); } } catch (Exception ex) { } } scope.Complete(); } return(result > 0 ? result : 0); }
public Int32 SavePublisherBooks(Publisher_BEL Publisher, IEnumerable <BooksDetails_BEL> Books) { Publisher_DAL objDal = new Publisher_DAL(); try { return(objDal.SavePublisherBooks(Publisher, Books)); } catch (Exception ex) { throw; } finally { objDal = null; } }
public Int32 SavePublisher(Publisher_BEL objBel) { Publisher_DAL objDal = new Publisher_DAL(); try { return(objDal.SavePublishers(objBel)); } catch (Exception ex) { throw; } finally { objDal = null; } }
public Int32 UpdatePublisherRecord(Publisher_BEL objBel) { Publisher_DAL objDal = new Publisher_DAL(); try { return(objDal.UpdatePublisherRecord(objBel)); } catch (Exception ex) { throw; } finally { objDal = null; } }
public ActionResult Save(Publisher_BEL Publisher) { if (ModelState.IsValid) { if (Publisher.PublisherId > 0) { Publisher_BLL.UpdatePublisherRecord(Publisher); } else { Publisher_BLL.SavePublisher(Publisher); } return(RedirectToAction("Index")); } else { return(View(Publisher)); } }
public IEnumerable <Publisher_BEL> GetPublisherRecords() { List <Publisher_BEL> publishers = new List <Publisher_BEL>(); using (TransactionScope scope = new TransactionScope()) { using (SqlConnection conn = new SqlConnection(conStr)) { try { conn.Open(); using (SqlCommand cmd = new SqlCommand("FetchPublishers_Sp", conn)) { cmd.CommandType = CommandType.StoredProcedure; using (SqlDataReader reader = cmd.ExecuteReader()) { //todo probar linq while (reader.Read()) { Publisher_BEL publisher = new Publisher_BEL( reader["PublisherName"].ToString()); publisher.PublisherId = Convert.ToInt32(reader["PublisherId"]); publisher.Active = Convert.ToBoolean(reader["Active"]); publishers.Add(publisher); } } } } catch (Exception ex) { } } scope.Complete(); } return(publishers); }
public Publisher_BEL GetPublisherRecord(int id) { Publisher_BEL publisher = null; using (TransactionScope scope = new TransactionScope()) { using (SqlConnection conn = new SqlConnection(conStr)) { try { conn.Open(); using (SqlCommand cmd = new SqlCommand("FetchPublisher_Sp", conn)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("PublisherId", id); using (SqlDataReader reader = cmd.ExecuteReader()) { //todo probar linq while (reader.Read()) { publisher = new Publisher_BEL( reader["PublisherName"].ToString()); publisher.PublisherId = Convert.ToInt32(reader["PublisherId"]); publisher.Active = Convert.ToBoolean(reader["Active"]); } } } } catch (Exception ex) { } } scope.Complete(); } return(publisher); }
public ActionResult Remove(Publisher_BEL Publisher) { int result = Publisher_BLL.DeletePublisherRecord(Publisher.PublisherId); return(View("Index", Publisher_BLL.GetPublisherRecords())); }
public ActionResult Create(Publisher_BEL Publisher) { return(View(Publisher)); }
public PublisherBooksModel(Publisher_BEL Publisher, IEnumerable <BooksDetails_BEL> AllBooks, IEnumerable <BooksDetails_BEL> PublisherBooks) { this.Publisher = Publisher; this.AllBooks = AllBooks; this.PublisherBooks = PublisherBooks; }