コード例 #1
0
 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));
     }
 }
コード例 #2
0
 private bool RelatedBlogItemExists(int id)
 {
     using (ApplicationDbContextcs db = new ApplicationDbContextcs())
     {
         return(db.blogItem.Any(e => e.RelatedID == id));
     }
 }
コード例 #3
0
 private bool UserAcccountExists(int id)
 {
     using (ApplicationDbContextcs db = new ApplicationDbContextcs())
     {
         return(db.userAccount.Any(e => e.UId == id));
     }
 }
コード例 #4
0
 private bool ConvBlogItemExists(int id)
 {
     using (ApplicationDbContextcs db = new ApplicationDbContextcs())
     {
         return(db.ConvBlogItem.Any(e => e.ConvBlogItemID == id));
     }
 }
コード例 #5
0
 // GET: UserAcccounts
 public async Task <IActionResult> Index()
 {
     using (ApplicationDbContextcs db = new ApplicationDbContextcs())
     {
         return(View(await db.userAccount.ToListAsync()));
     }
 }
コード例 #6
0
        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));
            }
        }
コード例 #7
0
        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));
            }
        }
コード例 #8
0
 private List <BlogItem> GetBlogItemLeafList(int id)
 {
     using (ApplicationDbContextcs db = new ApplicationDbContextcs())
     {
         var blogList = db.blogItem
                        .Where(m => m.RelatedID == id).ToList();
         return(blogList);
     }
 }
コード例 #9
0
ファイル: AppController.cs プロジェクト: itayEss/WebProjectCS
 public IActionResult Settings()
 {
     using (ApplicationDbContextcs db = new ApplicationDbContextcs())
     {
         addViewBags();
         var user = db.userAccount;
         return(View(user.ToList()));
     }
 }
コード例 #10
0
ファイル: AppController.cs プロジェクト: itayEss/WebProjectCS
        public IActionResult Blog()
        {
            using (ApplicationDbContextcs db = new ApplicationDbContextcs())
            {
                addViewBags();
                var convBlogItem = db.convBlogItem;

                return(View(convBlogItem.ToList()));
            }
        }
コード例 #11
0
        public IActionResult GetAllLeafs(int?id)
        {
            using (ApplicationDbContextcs db = new ApplicationDbContextcs())
            {
                List <BlogItem> list = new List <BlogItem>();

                addAllLeafs((int)id, list);

                return(Json(list));
            }
        }
コード例 #12
0
 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);
         }
     }
 }
コード例 #13
0
        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"));
            }
        }
コード例 #14
0
        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));
            }
        }
コード例 #15
0
        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));
            }
        }
コード例 #16
0
        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));
            }
        }
コード例 #17
0
        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));
            }
        }
コード例 #18
0
        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));
            }
        }
コード例 #19
0
        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);
                    }
                }
            }
        }
コード例 #20
0
 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"); }
     }
 }
コード例 #21
0
        // 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));
            }
        }
コード例 #22
0
        // 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));
            }
        }
コード例 #23
0
        // 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));
            }
        }
コード例 #24
0
ファイル: AppController.cs プロジェクト: itayEss/WebProjectCS
 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());
 }
コード例 #25
0
ファイル: AppController.cs プロジェクト: itayEss/WebProjectCS
 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());
 }
コード例 #26
0
        // 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));
            }
        }
コード例 #27
0
        // 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));
            }
        }
コード例 #28
0
        //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"));
            }
        }
コード例 #29
0
        // 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()));
            }
        }