public ActionResult PBFactTemplate(int id, int fact_id) { int uid; string utoken; HttpCookie cookie = Request.Cookies["User"]; if (cookie != null) { uid = int.Parse(cookie["id"]); utoken = cookie["token"]; } else { uid = 0; utoken = null; } if (auth.CheckAuthStatus(uid, utoken) && auth.GetCurrentUser(cookie)["Role"] == "1") { ViewBag.RoleNum = auth.GetCurrentUser(cookie)["Role"]; ViewBag.PID = id; ViewBag.User = auth.GetCurrentUser(cookie)["User"]; ViewBag.Role = db.Roles.Find(int.Parse(auth.GetCurrentUser(cookie)["Role"])).Name; ViewBag.UID = id; ViewBag.Roles = db.Roles; ViewBag.Companies = db.Company.OrderBy(a => a.Name); ViewBag.Part = "Products"; if (fact_id == 0) { return(View(new ProductBulletFact { })); } else { ProductBulletFact a = db.ProductBulletFact.Find(fact_id); return(View(a)); } } else { return(Redirect("~/Login")); } }
public ActionResult PBFactTemplate(int id, int fact_id, ProductBulletFact u) { int uid; string utoken; HttpCookie cookie = Request.Cookies["User"]; if (cookie != null) { uid = int.Parse(cookie["id"]); utoken = cookie["token"]; } else { uid = 0; utoken = null; } if (auth.CheckAuthStatus(uid, utoken) && auth.GetCurrentUser(cookie)["Role"] == "1") { ViewBag.RoleNum = auth.GetCurrentUser(cookie)["Role"]; ViewBag.User = auth.GetCurrentUser(cookie)["User"]; ViewBag.Role = db.Roles.Find(int.Parse(auth.GetCurrentUser(cookie)["Role"])).Name; if (fact_id == 0) { u.ProductID = int.Parse(Request.Form["PID"]); db.ProductBulletFact.Add(u); } else { db.ProductBulletFact.Find(id).Fact = u.Fact; } db.SaveChanges(); return(Redirect("~/Product/" + int.Parse(Request.Form["PID"]) + "/Facts")); } else { return(Redirect("~/Login")); } }