public void DeleteAuthor(int id) { AUTHOR author = dataAccess.AUTHORs.Single(aut => aut.AUTHORID == id); dataAccess.AUTHORs.DeleteOnSubmit(author); dataAccess.SaveChanges(); }
public void DeleteAuthor(AuthorModel Author) { if (Author == null) { throw new ArgumentNullException(); } using (AppTourEntities data = new AppTourEntities()) { AUTHOR current = data.AUTHOR.Where(p => p.ID == Author.Id).SingleOrDefault(); if (current != null) { try { data.DeleteObject(current); data.SaveChanges(); } catch (Exception e) { if (e.InnerException != null) { throw new Exception(e.InnerException.Message); } throw; } } } }
public void Delete(AUTHOR author) { using (var db = new LibDb()) { using (DbContextTransaction transaction = db.Database.BeginTransaction()) { db.AUTHORs.Attach(author); foreach (var bo in author.BOOKs) { db.BOOKs.Attach(bo); } try { author.BOOKs.Clear(); db.AUTHORs.Remove(author); db.SaveChanges(); transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); } } } }
public Tuple <Author, AuthorValidation> CreateAuthor(Author author) { AuthorValidation validation = new AuthorValidation(author); if (validation.IsValid) { string authorFirstName = author.FirstName; if (author.FirstName != null) { author.FirstName = authorFirstName.Substring(0, 1).ToUpper() + authorFirstName.Substring(1); } string authorLastName = author.LastName; author.LastName = authorLastName.Substring(0, 1).ToUpper() + authorLastName.Substring(1); AUTHOR repoAUTHOR = _Repo.CreateAuthor(Mapper.Map <Author, AUTHOR>(author)); if (repoAUTHOR == null) { validation.FailedToCreateAuthor(nameof(author.FirstName)); } else { Author newAuthor = Mapper.Map <Author>(repoAUTHOR); if (newAuthor != null) { return(new Tuple <Author, AuthorValidation>(newAuthor, validation)); } validation.FailedToCreateAuthor(nameof(author.LastName)); } } return(new Tuple <Author, AuthorValidation>(null, validation)); }
public IHttpActionResult PutAUTHOR(int id, AUTHOR aUTHOR) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != aUTHOR.ID) { return(BadRequest()); } db.Entry(aUTHOR).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!AUTHORExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public void Update(AUTHOR authorObj) { using (var db = new LibDb()) { var b = db.AUTHORs.Include(x => x.BOOKs).ToList().Find(d => d.Aid == authorObj.Aid); b.BOOKs.Clear(); db.SaveChanges(); } var newBooks = authorObj.BOOKs; authorObj.BOOKs = new List <BOOK>(); using (var db = new LibDb()) { db.AUTHORs.Attach(authorObj); db.Entry(authorObj).State = EntityState.Modified; foreach (var book in newBooks) { db.BOOKs.Attach(book); authorObj.BOOKs.Add(book); } db.SaveChanges(); } }
public Tuple <Author, AuthorValidation> EditAuthor(Author author) { AuthorValidation validation = new AuthorValidation(author); if (validation.IsValid) { string authorFirstName = author.FirstName; if (author.FirstName != null) { author.FirstName = authorFirstName.Substring(0, 1).ToUpper() + authorFirstName.Substring(1); } string authorLastName = author.LastName; author.LastName = authorLastName.Substring(0, 1).ToUpper() + authorLastName.Substring(1); AUTHOR repoAUTHOR = _Repo.EditAuthor(Mapper.Map <Author, AUTHOR>(author)); if (repoAUTHOR != null) { Author editedAuthor = Mapper.Map <AUTHOR, Author>(repoAUTHOR); if (editedAuthor != null) { return(new Tuple <Author, AuthorValidation>(editedAuthor, validation)); } } else { validation.DoesNotExistOnServer(nameof(author.LastName)); } } return(new Tuple <Author, AuthorValidation>(null, validation)); }
public ActionResult Create(AUTHOR author, HttpPostedFileBase thumbnail) { try { if (ModelState.IsValid) { if (thumbnail != null && !String.IsNullOrEmpty(thumbnail.FileName)) { String fname = Generator.RandomString(10) + "." + thumbnail.FileName.Split('.')[thumbnail.FileName.Split('.').Length - 1]; string path = Server.MapPath("~/UserImages/") + fname; author.THUMBNAIL_PATH = "/UserImages/" + fname; thumbnail.SaveAs(path); } else { author.THUMBNAIL_PATH = "/UserImages/avatar.png"; } AuthorModel.Create(author); ViewBag.Message = SuccessMessage.AUTHOR_ADDED; } else { ViewBag.ErrorMessage = ErrorMessage.REQUIRED_ASTERIC_FIELDS; } return(View()); } catch { ViewBag.ErrorMessage = ErrorMessage.INTERNAL_ERROR; return(View()); } }
public void UpdateAuthor(AuthorModel Author) { using (AppTourEntities data = new AppTourEntities()) { AUTHOR current = data.AUTHOR.Where(x => Author.Id == x.ID).SingleOrDefault(); if (current != null) { try { current.ENTERPRISE = data.ENTERPRISE.Where(f => f.ID == Author.Id).FirstOrDefault(); current.NAME = Author.Name; current.REALNAME = Author.RealName; current.EMAIL = Author.Email; current.CREATION_DATE = Author.CreationDate; current.UPDATE_DATE = DateTime.Now; data.SaveChanges(); } catch (Exception e) { if (e.InnerException != null) { throw new Exception(e.InnerException.Message); } throw; } } } }
public Guid InsertAuthor(AuthorModel Author) { Guid id = Guid.NewGuid(); if (Author == null) { throw new NullReferenceException(); } using (AppTourEntities data = new AppTourEntities()) { AUTHOR _new = new AUTHOR { ID = id, ENTERPRISE = data.ENTERPRISE.Where(f => f.ID == Author.Enterprise.Id).FirstOrDefault(), NAME = Author.Name, REALNAME = Author.RealName, EMAIL = Author.Email, CREATION_DATE = DateTime.Now, UPDATE_DATE = DateTime.Now }; data.AUTHOR.AddObject(_new); data.SaveChanges(); } return(id); }
public ActionResult DeleteConfirmed(int id) { AUTHOR aUTHOR = db.AUTHORs.Find(id); db.AUTHORs.Remove(aUTHOR); db.SaveChanges(); return(RedirectToAction("Index")); }
public void CreateNew(AUTHOR author) { using (var db = new LibDB()) { db.AUTHOR.Add(author); db.SaveChanges(); } }
public void Add(AUTHOR authorObj) { using (var db = new swagbaseEntities1()) { db.AUTHORs.Add(authorObj); db.SaveChanges(); } }
public void Update(AUTHOR authorObj) { using (var db = new LibraryDBEntities1()) { db.AUTHORs.Attach(authorObj); db.Entry(authorObj).State = EntityState.Modified; Shared.save(db); } }
public ActionResult ThemTacGia(String tenTG) { AUTHOR tg = new AUTHOR(); tg.NAME = tenTG; db.AUTHOR.Add(tg); db.SaveChanges(); return(RedirectToAction("ThemSach")); }
public void Add(AUTHOR authobj) { using (var db = new Libdb()) { db.AUTHOR.Add(authobj); db.Entry(authobj).State = EntityState.Added; db.SaveChanges(); } }
public void Update(AUTHOR authobj) { using (var db = new Libdb()) { db.AUTHOR.Attach(authobj); db.Entry(authobj).State = EntityState.Modified; db.SaveChanges(); } }
public void Delete(AUTHOR authorObj) { using (var db = new swagbaseEntities1()) { AUTHOR athID = db.AUTHORs.Find(authorObj.Aid); db.AUTHORs.Remove(athID); db.SaveChanges(); } }
// GET: Author/Details/5 public ActionResult Details(int id) { AUTHOR author = AuthorModel.Filter(id); if (author == null) { return(HttpNotFound()); } return(View(author)); }
public ActionResult Edit([Bind(Include = "ID,FIRST_NAME,LAST_NAME,ADDRESS,EMAIL,CONTACT_NO,EDUCATION,SPECIALIZATION,REMARKS")] AUTHOR aUTHOR) { if (ModelState.IsValid) { db.Entry(aUTHOR).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(aUTHOR)); }
public ActionResult Edit([Bind(Include = "Aid,FirstName,LastName,BirthYear")] AUTHOR aUTHOR) { if (ModelState.IsValid) { db.Entry(aUTHOR).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(aUTHOR)); }
public void createAuthor(string firstName, string lastName, string birthYear) { AuthorRepository authorManagerObj = new AuthorRepository(); AUTHOR author = new AUTHOR(); author.FirstName = firstName; author.LastName = lastName; author.BirthYear = birthYear; authorManagerObj.CreateNew(author); }
public ActionResult Create([Bind(Include = "Aid,FirstName,LastName,BirthYear")] AUTHOR aUTHOR) { if (ModelState.IsValid) { db.AUTHORs.Add(aUTHOR); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(aUTHOR)); }
public void editAuthor(string firstName, string lastName, string birthYear, int Aid) { AuthorRepository authorManagerObj = new AuthorRepository(); AUTHOR author = new AUTHOR(); author.FirstName = firstName; author.LastName = lastName; author.BirthYear = birthYear; author.Aid = Aid; authorManagerObj.Edit(author); }
//Hämtar en specifik författare static public Author getAuthor(int id) { AUTHOR aauthor = _eAuthorObj.Read(id); Author authorObj = Mapper.Map <Author>(aauthor); authorObj.FirstName = authorObj.FirstName; authorObj.LastName = authorObj.LastName; authorObj.BirthYear = authorObj.BirthYear; authorObj.BooksList = Mapper.Map <List <BOOK>, List <Book> >(aauthor.BOOKs.ToList()); return(authorObj); }
public IHttpActionResult GetAUTHOR(int id) { AUTHOR aUTHOR = db.AUTHORs.Find(id); if (aUTHOR == null) { return(NotFound()); } return(Ok(aUTHOR)); }
public ActionResult Create([Bind(Include = "ID,FIRST_NAME,LAST_NAME,ADDRESS,EMAIL,CONTACT_NO,EDUCATION,SPECIALIZATION,REMARKS")] AUTHOR aUTHOR) { if (ModelState.IsValid) { db.AUTHORs.Add(aUTHOR); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(aUTHOR)); }
public IHttpActionResult PostAUTHOR(AUTHOR aUTHOR) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.AUTHORs.Add(aUTHOR); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = aUTHOR.ID }, aUTHOR)); }
public void Remove(AUTHOR auth) { using (var db = new Libdb()) { var au = db.AUTHOR.FirstOrDefault(a => a.Aid == auth.Aid); au.BOOK.Clear(); db.AUTHOR.Remove(au); db.SaveChanges(); } }
/* * public void RemoveProjectReference(int depid, int projid) * { * using (var db = new dbprojectEntities()) * { * _departmentObj = db.departments.ToList().Find(d => d.depid == depid); * if(_departmentObj.projects1.ToList().Exists(x => x.projid == projid)) //Check that there is a row in the intermediate table * { * project projectObject = db.projects.ToList().Find(p => p.projid == projid); * _departmentObj.projects1.Remove(projectObject); * db.SaveChanges(); * } * } * }*/ public void removeBookReference(int aId, string removeISBN) { using (var db = new LibraryDBEntities1()) { _authorObj = db.AUTHORs.Include(x => x.BOOKs).ToList().Find(a => a.Aid == aId); if (_authorObj.BOOKs.ToList().Exists(b => b.ISBN == removeISBN)) { BOOK bookObj = db.BOOKs.ToList().Find(b => b.ISBN == removeISBN); _authorObj.BOOKs.Remove(bookObj); Shared.save(db); } } }