Exemplo n.º 1
0
 public string UpdateReadList(ReadList newReadList)
 {
     using (ReadListContext db = new ReadListContext())
     {
         ReadList temp = db.ReadLists.Find(newReadList.Id);
         if (temp == null)
         {
             return("Update failed, because row with this id does not exist.");
         }
         if (string.IsNullOrEmpty(newReadList.AuthorName))
         {
             return("Insert failed, because authorName should not be null or empty string.");
         }
         if (string.IsNullOrEmpty(newReadList.BookTitle))
         {
             return("Insert failed, because bookTitle should not be null or empty string.");
         }
         if (newReadList.Page <= 0)
         {
             return("Update failed, because book must have more pages than zero or less.");
         }
         if (newReadList.Rating <= 0 || newReadList.Rating > 5)
         {
             return("Update failed, because rating must be more than one and less than five.");
         }
         temp.AuthorName      = newReadList.AuthorName;
         temp.BookTitle       = newReadList.BookTitle;
         temp.Page            = newReadList.Page;
         temp.Rating          = newReadList.Rating;
         temp.ReadingDate     = newReadList.ReadingDate;
         db.Entry(temp).State = EntityState.Modified;
         db.SaveChanges();
         return("Update successful!");
     }
 }
Exemplo n.º 2
0
 public string DeleteById(int id)
 {
     using (ReadListContext db = new ReadListContext())
     {
         ReadList readList = db.ReadLists.Find(id);
         if (readList != null)
         {
             db.Entry(readList).State = EntityState.Deleted;
             db.SaveChanges();
             return("Delete successful!");
         }
         else
         {
             return("Delete failed, Row with this id does not exist.");
         }
     }
 }