public async Task <IActionResult> Edit(int id, [Bind("UId,FirstName,LastName,Email,UserName,Password,ConfirmPassword,UPriv")] UserAcccount userAcccount) { if (id != userAcccount.UId) { return(NotFound()); } using (ApplicationDbContextcs db = new ApplicationDbContextcs()) { if (ModelState.IsValid) { try { db.Update(userAcccount); await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UserAcccountExists(userAcccount.UId)) { return(NotFound()); } else { throw; } } string url = @"../../App/Settings"; return(Redirect(url)); } return(View(userAcccount)); } }
private bool RelatedBlogItemExists(int id) { using (ApplicationDbContextcs db = new ApplicationDbContextcs()) { return(db.blogItem.Any(e => e.RelatedID == id)); } }
private bool UserAcccountExists(int id) { using (ApplicationDbContextcs db = new ApplicationDbContextcs()) { return(db.userAccount.Any(e => e.UId == id)); } }
private bool ConvBlogItemExists(int id) { using (ApplicationDbContextcs db = new ApplicationDbContextcs()) { return(db.ConvBlogItem.Any(e => e.ConvBlogItemID == id)); } }
// GET: UserAcccounts public async Task <IActionResult> Index() { using (ApplicationDbContextcs db = new ApplicationDbContextcs()) { return(View(await db.userAccount.ToListAsync())); } }
public async Task <IActionResult> Edit(int id, [Bind("BlogItemID,ConvID,Subject,Message")] BlogItem blogItem) { using (ApplicationDbContextcs db = new ApplicationDbContextcs()) { if (id != blogItem.BlogItemID) { return(NotFound()); } if (ModelState.IsValid) { try { db.Update(blogItem); await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BlogItemExists(blogItem.BlogItemID)) { return(NotFound()); } else { throw; } } string url = @"../../ConvBlogItems/Conversation/" + blogItem.ConvID; return(Redirect(url)); } ViewData["ConvID"] = blogItem.ConvID; return(View(blogItem)); } }
public async Task <IActionResult> Edit(int id, [Bind("ConvBlogItemID,ConvName,ConvCreatorName")] ConvBlogItem convBlogItem) { using (ApplicationDbContextcs db = new ApplicationDbContextcs()) { if (id != convBlogItem.ConvBlogItemID) { return(NotFound()); } if (ModelState.IsValid) { try { db.Update(convBlogItem); await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ConvBlogItemExists(convBlogItem.ConvBlogItemID)) { return(NotFound()); } else { throw; } } return(RedirectToAction("Blog", "App")); } return(View(convBlogItem)); } }
private List <BlogItem> GetBlogItemLeafList(int id) { using (ApplicationDbContextcs db = new ApplicationDbContextcs()) { var blogList = db.blogItem .Where(m => m.RelatedID == id).ToList(); return(blogList); } }
public IActionResult Settings() { using (ApplicationDbContextcs db = new ApplicationDbContextcs()) { addViewBags(); var user = db.userAccount; return(View(user.ToList())); } }
public IActionResult Blog() { using (ApplicationDbContextcs db = new ApplicationDbContextcs()) { addViewBags(); var convBlogItem = db.convBlogItem; return(View(convBlogItem.ToList())); } }
public IActionResult GetAllLeafs(int?id) { using (ApplicationDbContextcs db = new ApplicationDbContextcs()) { List <BlogItem> list = new List <BlogItem>(); addAllLeafs((int)id, list); return(Json(list)); } }
private void addAllLeafs(int id, List <BlogItem> list) { using (ApplicationDbContextcs db = new ApplicationDbContextcs()) { var blogItems = GetBlogItemLeafList((int)id); foreach (var item in blogItems) { list.Add(item); addAllLeafs(item.BlogItemID, list); } } }
public async Task <IActionResult> DeleteConfirmed(int id) { using (ApplicationDbContextcs db = new ApplicationDbContextcs()) { var convBlogItem = await db.ConvBlogItem.FindAsync(id); db.ConvBlogItem.Remove(convBlogItem); await db.SaveChangesAsync(); return(RedirectToAction("Blog", "App")); } }
public async Task <IActionResult> DeleteConfirmed(int id) { using (ApplicationDbContextcs db = new ApplicationDbContextcs()) { var userAcccount = await db.userAccount.FindAsync(id); db.userAccount.Remove(userAcccount); await db.SaveChangesAsync(); string url = @"../../App/Settings"; return(Redirect(url)); } }
public async Task <IActionResult> Create([Bind("ConvBlogItemID,ConvName,ConvCreatorName")] ConvBlogItem convBlogItem) { using (ApplicationDbContextcs db = new ApplicationDbContextcs()) { if (ModelState.IsValid) { db.Add(convBlogItem); await db.SaveChangesAsync(); return(RedirectToAction("Blog", "App")); } return(View(convBlogItem)); } }
public async Task <IActionResult> DeleteConfirmed(int id) { using (ApplicationDbContextcs db = new ApplicationDbContextcs()) { var chiledBlogItemList = await db.blogItem.Where(p => p.RelatedID == id).ToListAsync(); var blogItem = await db.blogItem.FindAsync(id); int cid = blogItem.ConvID; DeleteLeafs(chiledBlogItemList); DeleteBlogItem(blogItem); string url = @"../../ConvBlogItems/Conversation/" + cid; return(Redirect(url)); } }
public async Task <IActionResult> Create([Bind("UId,FirstName,LastName,Email,UserName,Password,ConfirmPassword,UPriv")] UserAcccount userAcccount) { using (ApplicationDbContextcs db = new ApplicationDbContextcs()) { if (ModelState.IsValid) { db.Add(userAcccount); await db.SaveChangesAsync(); string url = @"../../App/Settings"; return(Redirect(url)); } return(View(userAcccount)); } }
public async Task <IActionResult> Create([Bind("BlogItemID,ConvID,UID,Subject,Message,RelatedID")] BlogItem blogItem) { using (ApplicationDbContextcs db = new ApplicationDbContextcs()) { if (ModelState.IsValid) { blogItem.Date = DateTime.Now; db.Add(blogItem); await db.SaveChangesAsync(); string url = @"../../ConvBlogItems/Conversation/" + blogItem.ConvID; return(Redirect(url)); } return(View(blogItem)); } }
private async void DeleteLeafs(List <BlogItem> list) { using (ApplicationDbContextcs db = new ApplicationDbContextcs()) { while (list.Count != 0) { foreach (BlogItem bi in list) { var chiledBlogItemList = await db.blogItem.Where(p => p.RelatedID == bi.BlogItemID).ToListAsync(); DeleteBlogItem(bi); DeleteLeafs(chiledBlogItemList); } } } }
private void DeleteBlogItem(BlogItem blogItem) { using (ApplicationDbContextcs db = new ApplicationDbContextcs()) { try { Trace.WriteLine("Trying to delete blogItem"); if (blogItem != null) { db.blogItem.Remove(blogItem); db.SaveChanges(); } } catch (Exception e) { Trace.WriteLine("Problem While deleting blog item"); } } }
// GET: UserAcccounts/Edit/5 public async Task <IActionResult> Edit(int?id) { if (id == null) { return(NotFound()); } using (ApplicationDbContextcs db = new ApplicationDbContextcs()) { var userAcccount = await db.userAccount.FindAsync(id); if (userAcccount == null) { return(NotFound()); } return(View(userAcccount)); } }
// GET: ConvBlogItems/Edit/5 public async Task <IActionResult> Edit(int?id) { using (ApplicationDbContextcs db = new ApplicationDbContextcs()) { if (id == null) { return(NotFound()); } var convBlogItem = await db.ConvBlogItem.FindAsync(id); if (convBlogItem == null) { return(NotFound()); } return(View(convBlogItem)); } }
// GET: BlogItems/Edit/5 public async Task <IActionResult> Edit(int?id, int?cid) { using (ApplicationDbContextcs db = new ApplicationDbContextcs()) { if (id == null) { return(NotFound()); } ViewData["ConvID"] = cid; var blogItem = await db.blogItem.FindAsync(id); if (blogItem == null) { return(NotFound()); } return(View(blogItem)); } }
public IActionResult Register(UserAcccount account) { try { addViewBags(); } catch (Exception e) { Console.WriteLine(e.StackTrace); } if (ModelState.IsValid) { using (ApplicationDbContextcs db = new ApplicationDbContextcs()) { db.userAccount.Add(account); db.SaveChanges(); } ModelState.Clear(); ViewBag.Message = account.FirstName + " " + account.LastName + " Successfully registered."; } return(View()); }
public IActionResult Login(UserAcccount user) { using (ApplicationDbContextcs db = new ApplicationDbContextcs()) { try { var usr = db.userAccount.Single(u => u.UserName == user.UserName && u.Password == user.Password); HttpContext.Session.SetInt32("UserID", usr.UId); HttpContext.Session.SetString("UserName", usr.UserName.ToString()); HttpContext.Session.SetInt32("UserPriv", usr.UPriv); return(Redirect("Index")); } catch (Exception e) { ModelState.AddModelError("", "UserName or Password is wrong!"); } } return(View()); }
// GET: UserAcccounts/Details/5 public async Task <IActionResult> Details(int?id) { if (id == null) { return(NotFound()); } using (ApplicationDbContextcs db = new ApplicationDbContextcs()) { var userAcccount = await db.userAccount .FirstOrDefaultAsync(m => m.UId == id); if (userAcccount == null) { return(NotFound()); } return(View(userAcccount)); } }
// GET: BlogItems/Details/5 public async Task <IActionResult> Details(int?id) { using (ApplicationDbContextcs db = new ApplicationDbContextcs()) { if (id == null) { return(NotFound()); } var blogItem = await db.blogItem .FirstOrDefaultAsync(m => m.BlogItemID == id); if (blogItem == null) { return(NotFound()); } return(View(blogItem)); } }
//private readonly ApplicationDbContextcs _context; //public UserAcccountsController(ApplicationDbContextcs context) //{ // _context = context; //} public IActionResult GetUserNameById(int?id) { using (ApplicationDbContextcs db = new ApplicationDbContextcs()) { var usr = (from us in db.userAccount where us.UId == id select us.UserName); if (usr.Count() > 0) { string name = (from us in db.userAccount where us.UId == id select us.UserName).First().ToString(); //return Json(name); return(Json(name)); } return(Json("UnKnownUserName")); } }
// GET: ConvBlogItems public async Task <IActionResult> Conversation(int?id) { using (ApplicationDbContextcs db = new ApplicationDbContextcs()) { var bi = db.blogItem .Where(b => b.ConvID == id) .Where(b => b.RelatedID == -1); /* * var bi = from bit in db.blogItem * join us in db.userAccount on bit.UID equals us.UId * where (bit.ConvID == id && bit.RelatedID == -1) * select new * { * bit, * UName = us.UserName * }; */ ViewData["ConvID"] = id; return(View(await bi.ToListAsync())); } }