public string AddSubSection(SubSectionModel subSectionModel) { string success = ""; try { using (var db = new BookDbContext()) { //var bookSubSection = new SubSection() var subSection = new SubSection() { //Id = subSectionModel.Id BookId = subSectionModel.BookId, ChapterId = subSectionModel.ChapterId, SectionId = subSectionModel.SectionId, SubSectionTitle = subSectionModel.SubSectionTitle, SubSectionOrder = subSectionModel.SubSectionOrder, SubSectionContents = subSectionModel.SubSectionContents, }; db.SubSections.Add(subSection); db.SaveChanges(); success = "ok"; } } catch (Exception ex) { success = Helpers.ErrorDetails(ex); } return(success); }
public string UpdateSubSection(SubSectionModel subSectionModel) { string success = ""; try { using (var db = new BookDbContext()) { var bookSubSection = db.SubSections.Where(s => s.Id == subSectionModel.Id).FirstOrDefault(); if (bookSubSection == null) { success = "not found"; } else { bookSubSection.SubSectionTitle = subSectionModel.SubSectionTitle; bookSubSection.SubSectionOrder = subSectionModel.SubSectionOrder; bookSubSection.SubSectionContents = subSectionModel.SubSectionContents; db.SaveChanges(); success = "ok"; } } } catch (Exception ex) { success = Helpers.ErrorDetails(ex); } return(success); }
public SubSectionModel GetSubSection(int subSectionId) { var subSectionModel = new SubSectionModel(); using (var db = new BookDbContext()) { var dbSubSection = db.SubSections.Where(s => s.Id == subSectionId).FirstOrDefault(); if (dbSubSection != null) { subSectionModel.Id = dbSubSection.Id; subSectionModel.SubSectionTitle = dbSubSection.SubSectionTitle; subSectionModel.SubSectionOrder = dbSubSection.SubSectionOrder; subSectionModel.SubSectionContents = dbSubSection.SubSectionContents; } } return(subSectionModel); }