/// <summary> /// Creates a new reading log for a user /// </summary> /// <param name="log"></param> /// <returns>A newly created reading log</returns> public ReadingLog CreateReadingLog(ReadingLog log) { string sql = @"INSERT INTO ReadingLog (BookID, UserID, Minutes_read, Status, Type, Date) VALUES (@BookID, @UserID, @Minutes_read, @Status, @Type, @Date); SELECT CAST(SCOPE_IDENTITY() as int);"; try { using (SqlConnection conn = new SqlConnection(_connectionString)) { conn.Open(); SqlCommand cmd = new SqlCommand(sql, conn); cmd.Parameters.AddWithValue("@BookID", log.BookID); cmd.Parameters.AddWithValue("@UserID", log.UserID); cmd.Parameters.AddWithValue("@Minutes_read", log.MinutesRead); cmd.Parameters.AddWithValue("@Status", log.Status); cmd.Parameters.AddWithValue("@Type", log.Type); cmd.Parameters.AddWithValue("@Date", DateTime.Now); log.ID = (int)cmd.ExecuteScalar(); return(log); } } catch (SqlException ex) { throw; } }
public IActionResult PostReadingLogs(ReadingLog readingLog) { _context.ReadingLogs.Add(readingLog); _context.SaveChanges(); return(Ok()); }
protected override void Seed(ApplicationDbContext context) { // Create some test users // Create them via the user manager rather than adding them directly to handle // the security stamp and hashing var hasher = new PasswordHasher(); var user1 = new ApplicationUser { UserName = "******", Email = "*****@*****.**", Hometown = "Oz", SecurityStamp = Guid.NewGuid().ToString(), PasswordHash = hasher.HashPassword("Password@123") }; context.Users.Add(user1); // Create a reading log for user1 var user1Books = new List <Book> { new Book() { Author = "John Somnez", Title = "Soft Skills", DateCompleted = null, Media = BookMedia.Paper, Status = BookStatus.Future }, new Book() { Author = "James Joyce", Title = "Ulysses", DateCompleted = new DateTime(2016, 7, 2), Status = BookStatus.Abandoned, Media = BookMedia.Audio }, new Book() { Author = "Charles Dickens", Title = "The Old Curiosity Shop", DateCompleted = new DateTime(2016, 2, 2), Status = BookStatus.Finished, Media = BookMedia.Ebook } }; var user1Log = new ReadingLog() { User = user1, Name = "User 1's reading log", Books = user1Books }; context.ReadingLogs.Add(user1Log); context.SaveChanges(); }
/// <summary> Add a reading log line to the log </summary> /// <param name="LogLine"> Information to add to the log </param> public void Add_Log(string LogLine) { if (ReadingLog == null) { ReadingLog = new List <string>(); } ReadingLog.Add(DateTime.Now.Hour.ToString().PadLeft(2, '0') + ":" + DateTime.Now.Minute.ToString().PadLeft(2, '0') + ":" + DateTime.Now.Second.ToString().PadLeft(2, '0') + "." + DateTime.Now.Millisecond.ToString().PadLeft(3, '0') + " - " + LogLine); }
/// <summary> Add an empty line to the reading log </summary> public void Add_Log() { if (ReadingLog == null) { ReadingLog = new List <string>(); } ReadingLog.Add(String.Empty); }
public IActionResult UpdateReadingLog(ReadingLog readingLog) { var currentReadingLog = _context.ReadingLogs.Find(readingLog.Id); if (currentReadingLog == null) { return(NotFound()); } //readingLog. _context.SaveChanges(); return(Ok()); }
public ActionResult AddReadingLog(UserActivityViewModel model) { ActionResult result = null; if (!ModelState.IsValid) { result = View("UserActivity", model); } else { model.MinutesRead = model.MinutesRead + (model.HoursRead * 60); ReadingLog log = new ReadingLog(); log.UserID = model.UserID; log.BookID = model.BookID; log.MinutesRead = model.MinutesRead; log.Status = model.Status; log.Type = model.Type; //date gets added in DAL log = _db.CreateReadingLog(log); var testID = TempData["RoleID"]; // book does not exist or ISBN is wrong if (log.ID == 0) { ModelState.AddModelError("invalid-credentials", "The reading log was not successfully created."); result = View("UserActivity", model); } else { Session["Log"] = log; //not sure if needed... yet? } if (((User)Session["User"]).RoleID == 2) { result = RedirectToAction("UserActivity", "Home"); } else if (((User)Session["User"]).RoleID == 3) { result = RedirectToAction("UserActivity", "Home"); } } return(result); }
/// <summary> /// Returns a list of reading logs for a user /// </summary> /// <param name="userID"></param> /// <returns>A stack of reading logs</returns> public Stack <ReadingLog> GetReadingLog(int userID) { string sql = @"SELECT ReadingLog.ID AS ID, ReadingLog.BookID AS BookID, Book.Title AS Title, Users.ID AS UserID, Family.ID AS FamilyID, ReadingLog.Minutes_read AS Minutes_read, ReadingLog.Type AS Type, ReadingLog.Status AS Status, ReadingLog.Date AS Date FROM ReadingLog JOIN BOOK ON Book.ID = ReadingLog.BookID JOIN Users ON Users.ID = ReadingLog.UserID JOIN Family ON Users.FamilyID = Family.ID WHERE Users.ID = @UserID;" ; Stack <ReadingLog> logs = new Stack <ReadingLog>(); try { using (SqlConnection conn = new SqlConnection(_connectionString)) { conn.Open(); SqlCommand cmd = new SqlCommand(sql, conn); cmd.Parameters.AddWithValue("@UserID", userID); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { ReadingLog log = new ReadingLog { ID = Convert.ToInt32(reader["ID"]), BookID = Convert.ToInt32(reader["BookID"]), Title = Convert.ToString(reader["Title"]), UserID = Convert.ToInt32(reader["UserID"]), FamilyID = Convert.ToInt32(reader["FamilyID"]), MinutesRead = Convert.ToInt32(reader["Minutes_read"]), Type = Convert.ToString(reader["Type"]), Status = Convert.ToString(reader["Status"]), Date = Convert.ToDateTime(reader["Date"]), }; logs.Push(log); } } } catch (SqlException ex) { throw; } return(logs); }
public ActionResult Create(ReadingLog readingLog) { string bookName = readingLog.BookName; string authorName = readingLog.Author; readingLog.ClockIn = DateTime.Now; readingLog.ClockOut = DateTime.Now; readingLog.ReaderId = Convert.ToInt32(Session["ReaderId"]); readingLog.ReaderName = Convert.ToString(Session["ReaderName"]); int Id = Convert.ToInt32(Session["ReaderId"]); using (MyDataBaseEntities dc = new MyDataBaseEntities()) { dc.ReadingLog.Add(readingLog); dc.SaveChanges(); var readingLogList = dc.ReadingLog.Where(a => a.ReaderId == Id).ToList(); //var BookList = (readingLogList.Select(a => a.BookName)).ToList(); //dc.ReadingLog.Where(a => a.ReaderId == readingLog.ReaderId).Select(a =>a.BookName).ToList(); //return Redirect(ReaderDetails); //Console.Write(BookList); return(View("BookList", readingLogList)); } }