public RedirectToActionResult Delete(PracticeLog practice) { TempData["message"] = $"Practice was deleted."; context.PracticeLog.Remove(practice); context.SaveChanges(); return(RedirectToAction("Index")); }
private PracticeLog pretendShoot; //where the code to do the task actually comes from public override void Initialize(GameObject obj) //overrides the previous implementation called "Initialize" from the abstract "Ability" class/scriptable object { //the obj gameobject MUST have the "logic" script attached to it for the reference below to work (in this case, PracticeLog) pretendShoot = obj.GetComponent <PracticeLog>(); //passed in to get a reference to the script and store it in "pretendShoot" pretendShoot.Setup(); pretendShoot.pretendDamage = pretendDamage; //can set the values of the "PracticeLog" script (hidden in inspector ones) to the ones in this scriptable object pretendShoot.pretendRange = pretendRange; pretendShoot.pretendHitForce = pretendHitForce; }
public async Task <IActionResult> Stop() { var user = await userManager.GetUserAsync(User); // here I am checking if start was clicked // and practice exists in the database: string logID = HttpContext.Session.GetString("logID"); if (logID != null) { PracticeLog practice = context.PracticeLog .Where(p => p.PracticeLogID == logID) .OrderByDescending(p => p.Date) .FirstOrDefault(); practice.InProgress = false; practice.PracticeEndTime = DateTime.Now; TimeSpan span = practice.PracticeEndTime.Subtract(practice.PracticeStartTime); if (span.Hours > 0) { practice.Duration = $"{span.Hours} hours {span.Minutes} min"; } else { practice.Duration = $"{span.Minutes} min {span.Seconds} sec"; } return(View("PracticeDetails", practice)); } // if session is empty nothing happens // user cannot click stop without clicking start else { ViewBag.Practices = context.PracticeLog .Where(u => u.UserID == user.Id) .Where(u => u.InProgress != true) .OrderByDescending(u => u.PracticeLogID) .ToList(); return(View("Index")); } }
// saves practice details to the DB public IActionResult Save(PracticeLog practice) { if (ModelState.IsValid) { context.PracticeLog.Update(practice); context.SaveChanges(); string start = HttpContext.Session.GetString("start"); if (start != null) { HttpContext.Session.Remove("start"); } TempData["message"] = "Your practice details were saved."; return(RedirectToAction("Index")); } else { return(View("PracticeDetails", practice)); } }
public string InsertPracticeLog(PracticeLog Object) { string ReturnMess; try { //Controllers.Auth.AuthController auth = new Controllers.Auth.AuthController(); var UpdateTrail = System.DateTime.Now; var Existing = DB.PracticeLog.Where(o => o.StudentId.Equals(Object.StudentId) && o.Date.Equals(Object.Date)).FirstOrDefault(); if (Existing == null) { Object.CreatedBy = Username; Object.CreatedDate = UpdateTrail; Object.ModifiedBy = Username; Object.ModifiedDate = UpdateTrail; DB.PracticeLog.Add(Object); DB.SaveChanges(); ReturnMess = "1"; } else { Existing.PracticeHours = Object.PracticeHours; Existing.Song = Object.Song; Existing.InstrumentId = Object.InstrumentId; Existing.Description = Object.Description; Existing.ModifiedBy = Username; Existing.ModifiedDate = UpdateTrail; ReturnMess = DB.SaveChanges().ToString(); } return(ReturnMess); } catch (Exception ex) { throw new Exception("Error : " + ex.Message); } }
public async Task <IActionResult> Start() { var user = await userManager.GetUserAsync(User); PracticeLog pl = new PracticeLog(); pl.PracticeLogID = Guid.NewGuid().ToString(); pl.PracticeStartTime = DateTime.Now; pl.UserID = user.Id; pl.Date = DateTime.Now; pl.DayOfWeek = DateTime.Now.DayOfWeek; pl.InProgress = true; // setting new sessions for started practice HttpContext.Session.SetString("logID", pl.PracticeLogID); HttpContext.Session.SetString("start", $"Practice started at " + $"{pl.PracticeStartTime.ToShortTimeString()}"); context.PracticeLog.Add(pl); context.SaveChanges(); return(RedirectToAction("Index", pl)); }
public JsonResult InsertPracticeLog([FromBody] JObject data) { PracticeLog Log = data.ToObject <PracticeLog>(); return(Json(BsLogic.InsertPracticeLog(Log))); }