public ActionResult GetFile(HttpPostedFileBase file, Files files) { TDBContext db = new TDBContext(); int MID = Convert.ToInt32(TempData["UID"]); int id = Convert.ToInt32(TempData["UID"]); if (ModelState.IsValid) { if (file != null) { string fil = Path.GetFileName(file.FileName); string path = Path.Combine(Server.MapPath("/App_Data/Uploads/"), fil); file.SaveAs(path); files.URL = "/App_Data/Uploads/" + file.FileName; } Files fc = new Files { Title = files.Title, Description = files.Description, URL = files.URL, MissionID = MID }; db.Files.Add(fc); db.SaveChanges(); return(RedirectToAction("DList", new { id = MID })); } return(View(files)); }
public string GetAuthToken([FromBody] User user) { using (var db = new TDBContext()){ var existUser = db.Users.FirstOrDefault(u => u.Username == user.Username && u.Password == user.Password); if (existUser != null) { var requestAt = DateTime.Now; var expiresIn = requestAt + TokenAuthOption.ExpiresSpan; var token = GenerateToken(existUser, expiresIn); Console.WriteLine("So far so good initial request"); return(JsonConvert.SerializeObject(new RequestResult { State = RequestState.Success, Data = new { requested = requestAt, expiresIn = TokenAuthOption.ExpiresSpan.TotalSeconds, tokeyType = TokenAuthOption.TokenType, accessToken = token } })); } else { return(JsonConvert.SerializeObject(new RequestResult { State = RequestState.Failed, Msg = "Username or password is invalid" })); } } }
// ACTION METHODS FOR ACTIONPOINTS public ActionResult ActionPointsList(int id) { TDBContext db = new TDBContext(); TempData["ID"] = id; var GetList = (from p in db.ActionPoint join v in db.Progress on p.APID equals v.APID into ps from v in ps.DefaultIfEmpty() where p.MissionID == id select new ActionProgressVM { APID = p.APID, ActionPoint = p.ActionPoint, Catagory = p.Catagory, DueDate = p.DueDate, Status = v.Status, Responsible = p.Responsible, Priority = p.Priority, Remarks = p.Remarks, Percentage = v.Percentage }).ToList(); //var data = db.Database.SqlQuery<ActionProgressVM>("EXEC uspgetactionprog {0}", id).ToList(); return(View(GetList)); }
public ActionResult UpdateAction(ActionPoints model) { TDBContext db = new TDBContext(); int MID = Convert.ToInt32(TempData["ID"]); ActionPoints ac = new ActionPoints { APID = model.APID, Catagory = model.Catagory, Priority = model.Priority, ActionPoint = model.ActionPoint, DueDate = model.DueDate, Responsible = model.Responsible, Remarks = model.Remarks, MissionID = MID }; db.Entry(ac).State = EntityState.Modified; db.SaveChanges(); string message = "Recored has been updated successfully."; bool status = true; return(Json(new { status = status, message = message }, JsonRequestBehavior.AllowGet)); }
public ActionResult ACreate(ActionPoints actionPoints) { TDBContext db = new TDBContext(); string message = "Saved Successfully"; bool status = true; int MID = Convert.ToInt32(TempData["ID"]); ActionPoints ac = new ActionPoints { Catagory = actionPoints.Catagory, Priority = actionPoints.Priority, ActionPoint = actionPoints.ActionPoint, DueDate = actionPoints.DueDate, Responsible = actionPoints.Responsible, Remarks = actionPoints.Remarks, MissionID = MID }; db.ActionPoint.Add(ac); db.SaveChanges(); return(Json(new { status = status, message = message, id = db.ActionPoint.Max(x => x.APID) }, JsonRequestBehavior.AllowGet)); }
public PartialViewResult DownloadFiles() { TDBContext db = new TDBContext(); ViewBag.message = "file does not exist"; int MID = Convert.ToInt32(TempData["UID"]); var all = db.Files.Where(x => x.MissionID == MID).ToList(); //var data = db.Files.Find(all); //var filename = Path.GetFileName(FilePath.FileName); //var path = Request.MapPath("~/App_Data/Uploads/" + all.URL); if (all != null) { // var dir = new DirectoryInfo(Server.MapPath("/App_Data/Uploads/")); //FileInfo[] fileNames = dir.GetFiles(path); //List<string> items = new List<string>(); List <Files> files = new List <Files>(); foreach (var file in all) { file.URL.ToString(); file.FID.ToString(); //files.Add(file.URL); //files.Add(Convert.ToString(file.FID)); } return(PartialView("_DownloadFiles", all)); } return(ViewBag.message); }
// ACTION METHODS FOR PROGRESS public ActionResult ProgressList(int id) { TDBContext db = new TDBContext(); TempData["PID"] = id; var ProgressList = db.Progress.Where(x => x.APID == id).ToList(); return(View(ProgressList)); }
public ActionResult Create(ISM iSM) { TDBContext db = new TDBContext(); string message = "Saved Successfully"; bool status = true; db.ISM.Add(iSM); db.SaveChanges(); return(Json(new { status = status, message = message, id = db.ISM.Max(x => x.MissionID) }, JsonRequestBehavior.AllowGet)); }
public IList <User> getAllUsers() { using (var db = new TDBContext()){ var users = db.Users.Select(u => new User { Username = u.Username, first_name = u.first_name }); return(users.ToList()); } }
public ActionResult UpdateMission(ISM model) { TDBContext db = new TDBContext(); db.Entry(model).State = EntityState.Modified; db.SaveChanges(); string message = "Recored has been updated successfully."; bool status = true; return(Json(new { status = status, message = message }, JsonRequestBehavior.AllowGet)); }
public JsonResult RegisterUser([FromBody] JObject data) { JToken userToken = data; using (var db = new TDBContext()){ var exists = db.Users.Single(x => x.Username == (string)userToken.SelectToken("username")); if (exists == null) { Guid user_id = Guid.NewGuid(); String username = (string)userToken.SelectToken("username"); String first_name = (string)userToken.SelectToken("first_name"); String last_name = (string)userToken.SelectToken("last_name"); String email = (string)userToken.SelectToken("email"); String password = (string)userToken.SelectToken("password"); var user = new User(); user.UserID = user_id; user.Username = username; user.email = email; user.first_name = first_name; user.Password = password; user.last_name = last_name; try{ db.Users.Add(user); db.SaveChanges(); MailService.SendMessage(first_name, last_name, email, "Thank you for Registering with us!"); return(Json( new { success = true })); } catch (Exception e) { Console.WriteLine(e); return(Json( new { Message = "There was an issue, please try again later" })); } } else { return(Json( new { Message = "User Exists" })); } } }
public ActionResult Delete(int id) { TDBContext db = new TDBContext(); var mission = db.ISM.Where(x => x.MissionID == id).FirstOrDefault(); db.ISM.Remove(mission); db.SaveChanges(); string message = "Record has been deleted successfully"; bool status = true; return(Json(new { status = status, message = message }, JsonRequestBehavior.AllowGet)); }
public ActionResult GetMissions(int ID) { TDBContext db = new TDBContext(); ISM data = new ISM(); var getMission = db.ISM.Where(x => x.MissionID == ID).FirstOrDefault(); data.MissionID = getMission.MissionID; data.MStartDate = getMission.MStartDate; data.MEndDate = getMission.MEndDate; data.Program = getMission.Program; data.Type = getMission.Type; data.Rating = getMission.Rating; return(Json(new { success = true, data = data }, JsonRequestBehavior.AllowGet)); }
public ActionResult GetProgress(int ID) { TDBContext db = new TDBContext(); Progress data = new Progress(); var getMission = db.Progress.Where(x => x.ProgID == ID).FirstOrDefault(); data.ProgID = getMission.ProgID; data.ReportingDate = getMission.ReportingDate; data.Percentage = getMission.Percentage; data.Status = getMission.Status; return(Json(new { success = true, data = data }, JsonRequestBehavior.AllowGet)); }
public ActionResult GetActions(int ID) { TDBContext db = new TDBContext(); ActionPoints data = new ActionPoints(); var getMission = db.ActionPoint.Where(x => x.APID == ID).FirstOrDefault(); data.APID = getMission.APID; data.Catagory = getMission.Catagory; data.Priority = getMission.Priority; data.ActionPoint = getMission.ActionPoint; data.DueDate = getMission.DueDate; data.Responsible = getMission.Responsible; data.Remarks = getMission.Remarks; return(Json(new { success = true, data = data }, JsonRequestBehavior.AllowGet)); }
public JsonResult CheckUsername(String username) { using (var db = new TDBContext()){ var exists = db.Users.Single(x => x.Username == username); if (exists != null) { return(Json( new { exists = false })); } else { return(Json( new { exists = true })); } } }
public ActionResult FDelete(int ID) { using (var db = new TDBContext()) { int MID = Convert.ToInt32(TempData["UID"]); int id = Convert.ToInt32(TempData["UID"]); var data = db.Files.Find(ID); //var filename = Path.GetFileName(FilePath.FileName); var path = Request.MapPath(data.URL); if (System.IO.File.Exists(path)) { System.IO.File.Delete(path); ViewBag.deleteSuccess = "true"; } db.Files.Remove(data); db.SaveChanges(); return(RedirectToAction("DList", new { id = MID })); } }
public ActionResult UpdateProgress(Progress model) { TDBContext db = new TDBContext(); int MID = Convert.ToInt32(TempData["PID"]); Progress ac = new Progress { ProgID = model.ProgID, Status = model.Status, ReportingDate = model.ReportingDate, Percentage = model.Percentage, APID = MID }; db.Entry(ac).State = EntityState.Modified; db.SaveChanges(); string message = "Recored has been updated successfully."; bool status = true; return(Json(new { status = status, message = message }, JsonRequestBehavior.AllowGet)); }
public ActionResult PCreate(Progress progress) { TDBContext db = new TDBContext(); string message = "Saved Successfully"; bool status = true; int MID = Convert.ToInt32(TempData["PID"]); Progress ac = new Progress { ReportingDate = progress.ReportingDate, Percentage = progress.Percentage, Status = progress.Status, APID = MID }; db.Progress.Add(ac); db.SaveChanges(); return(Json(new { status = status, message = message, id = db.ActionPoint.Max(x => x.APID) }, JsonRequestBehavior.AllowGet)); }
// ACTION METHODS FOR ISM public ActionResult Index() { TDBContext db = new TDBContext(); return(View(db.ISM.ToList())); }