public ActionResult Register(tbl_Users u)
 {
     MyService.ServiceController myServiceController = new MyService.ServiceController();
     string newUser = myServiceController.Register(u.First_Name, u.Last_Name, u.Username, u.Password, u.Role_Id);
     ViewBag.Role_Id = new SelectList(db.tbl_Roles, "Role_Id", "Type");
     return View();
 }
        public ActionResult Login(tbl_Users u)
        {
            try
            {
                MyService.ServiceController myServiceController = new MyService.ServiceController();
                string user = myServiceController.Login(u.Username, u.Password);

                if (user == "UserCredentialsMatched")
                {
                    FormsAuthentication.SetAuthCookie(u.Username, true);
                    //HttpContext.User = new GenericPrincipal();
                    ViewBag.GreetingMessage = "Welcome " + u.Username;
                    return RedirectToAction("Index", "Home");
                }
                else
                {
                    ViewBag.Message = "Invalid Login Details - Please Try Again";
                    return View();
                }

            }
            catch (Exception ex)
            {
                ViewBag.Message = "Invalid Login Details - Please Try Again";
                return View();
            }
        }
 public ActionResult DeleteConfirmed(int id)
 {
     MyService.ServiceController myServiceController = new MyService.ServiceController();
     myServiceController.DeleteArticle(id, "TextArticle");
     return View();
 }
        public ActionResult UpdateArticle(tbl_Article a)
        {
            a.User_Id = db.tbl_Users.SingleOrDefault(x => x.Username == HttpContext.User.Identity.Name).User_Id;

            tbl_Comments com = new tbl_Comments();
            com = db.tbl_Comments.SingleOrDefault(x => x.Article_Id == a.Article_Id);
            if (com == null)
            {
                com = new tbl_Comments();
            }

            string commentContent = "";

            if (com.ArticleComment_Id != 0)
            {
                a.ArticleComment_Id = com.ArticleComment_Id;
                commentContent = com.ArticleComment_Content;
            }
            else
            {
                a.ArticleComment_Id = null;
                commentContent = "";
            }

            MyService.ServiceController myServiceController = new MyService.ServiceController();
            myServiceController.SubmitUpdatedArticle(a.Article_Id, a.Article_Name, a.Article_Description,
                a.Article_PublishDate, a.User_Id, a.MedaManager_Id, a.ArticleStatus_Id, a.Article_State_Id,
                commentContent, Convert.ToInt32(a.ArticleComment_Id), "TextArticle");
            return View();
        }
        public ActionResult SubmitArticle(tbl_Article a)
        {
            a.User_Id = db.tbl_Users.SingleOrDefault(x => x.Username == HttpContext.User.Identity.Name).User_Id;

            MyService.ServiceController myServiceController = new MyService.ServiceController();
            myServiceController.SubmitNewArticle(a.Article_Name, a.Article_Description, a.Article_PublishDate, a.User_Id,
                a.MedaManager_Id, a.ArticleStatus_Id, a.Article_State_Id, Convert.ToInt32(a.ArticleComment_Id), "TextArticle");

            ViewBag.MediaManager_ID =
                    new SelectList(
                        db.tbl_Users.Where(
                            x => x.Role_Id == 2),
                        "User_Id", "Username");
            return View();
        }
        public ActionResult Edit(tbl_Article a)
        {
            //if (ModelState.IsValid)
            //{
            //    db.Entry(tbl_Article).State = EntityState.Modified;
            //    db.SaveChanges();
            //    return RedirectToAction("Index");
            //}
            //ViewBag.ArticleStatus_Id = new SelectList(db.tbl_ArticleStatus, "ArticleStatus_Id", "ArticleStatus_Type", tbl_Article.ArticleStatus_Id);
            //ViewBag.User_Id = new SelectList(db.tbl_Users, "User_Id", "First_Name", tbl_Article.User_Id);
            //return View(tbl_Article);

            tbl_Users curretUser = db.tbl_Users.SingleOrDefault(x => x.Username == HttpContext.User.Identity.Name);

            //tbl_Article currArt = db.tbl_Article.SingleOrDefault(x => x.Article_Id == a.Article_Id);
            //a.Article_State_Id = currArt.Article_State_Id;

            if (curretUser.Role_Id == 1) //Reviewer
            {
                MyService.ServiceController myServiceController = new MyService.ServiceController();
                myServiceController.AcceptOrRejectArticleByReviewer(a.Article_Id, a.Article_Name, a.Article_Description,
                    a.Article_PublishDate, a.User_Id, a.MedaManager_Id, a.ArticleStatus_Id, a.Article_State_Id,
                    a.tbl_Comments.ArticleComment_Content, Convert.ToInt32(a.ArticleComment_Id), "TextArticle");

                ViewBag.ArticleStatus_Id = new SelectList(db.tbl_ArticleStatus, "ArticleStatus_Id", "ArticleStatus_Type");
                ViewBag.User_Id = new SelectList(db.tbl_Users, "User_Id", "First_Name");
                return View();
            }

            else if (curretUser.Role_Id == 2) //Media Manager
            {
                MyService.ServiceController myServiceController = new MyService.ServiceController();
                myServiceController.AcceptOrRejectArticleByMediaManager(a.Article_Id, a.Article_Name, a.Article_Description,
                    a.Article_PublishDate, a.User_Id, a.MedaManager_Id, a.ArticleStatus_Id, a.Article_State_Id,
                    a.tbl_Comments.ArticleComment_Content, Convert.ToInt32(a.ArticleComment_Id), "TextArticle");

                ViewBag.ArticleStatus_Id = new SelectList(db.tbl_ArticleStatus, "ArticleStatus_Id", "ArticleStatus_Type");
                ViewBag.User_Id = new SelectList(db.tbl_Users, "User_Id", "First_Name");
                return View();
            }

            return View();
        }