public async Task <ActionResult <Models.Bulletin> > Get() { Models.Bulletin Bulletin = new Models.Bulletin(); try { Models.BulletinMgr mgr = new Models.BulletinMgr(AppConfig); Bulletin = await mgr.GetBulletin(); } catch (Exception e) { System.Diagnostics.Trace.TraceError($"Error: Cannot find bulletin. Exception: {e.Message}"); } return(Bulletin); }
public async Task <IActionResult> AddBulletin(CreateBulletinModel inputModel) { if (!ModelState.IsValid) { return(View()); } try { var loggedInUser = HttpContext.User; var loggedInUserName = loggedInUser.Identity.Name; var id = (from u in context.RunningNumber where u.Type.Equals("BNumber") select u).FirstOrDefault(); var user = (from u in context.UserSspm where u.Username.Equals(loggedInUserName) select u).FirstOrDefault(); int num; if (id.Number == null) { num = 100001; } else { num = Convert.ToInt32(id.Number); num = num + 1; } Models.Bulletin ord = new Models.Bulletin { UserId = user.UserId, Subject = inputModel.Subject, Note = inputModel.Note, Time = DateTime.Now, Bnumber = num.ToString(), }; // Add the new object to the Orders collection. context.Bulletin.Add(ord); await context.SaveChangesAsync(); var query = from xx in context.RunningNumber where xx.Type.Equals("BNumber") select xx; foreach (RunningNumber RunTaskID in query) { RunTaskID.Number = num.ToString(); } // Submit the changes to the database. try { await context.SaveChangesAsync(); } catch (Exception e) { Console.WriteLine(e); // Provide for exceptions. } return(RedirectToAction("Index", "Home")); } catch (Exception ex) { var message = ex.Message; return(RedirectToAction("Index", "Home")); } }
public async Task OnGet() { Models.BulletinMgr mgr = new Models.BulletinMgr(AppConfig); Bulletin = await mgr.GetBulletin(); }