public ActionResult Post(bool IsNew, Spartan_BR_Peer_ReviewModel varSpartan_BR_Peer_Review)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (!_tokenManager.GenerateToken())
                    {
                        return(Json(null, JsonRequestBehavior.AllowGet));
                    }
                    _ISpartan_BR_Peer_ReviewApiConsumer.SetAuthHeader(_tokenManager.Token);


                    if (varSpartan_BR_Peer_Review.EvidenceRemoveAttachment != 0 && varSpartan_BR_Peer_Review.EvidenceFile == null)
                    {
                        varSpartan_BR_Peer_Review.Evidence = 0;
                    }

                    if (varSpartan_BR_Peer_Review.EvidenceFile != null)
                    {
                        var fileAsBytes = HttpPostedFileHelper.GetPostedFileAsBytes(varSpartan_BR_Peer_Review.EvidenceFile);
                        _ISpartane_FileApiConsumer.SetAuthHeader(_tokenManager.Token);
                        varSpartan_BR_Peer_Review.Evidence = (int)_ISpartane_FileApiConsumer.Insert(new Spartane_File()
                        {
                            File        = fileAsBytes,
                            Description = varSpartan_BR_Peer_Review.EvidenceFile.FileName,
                            File_Size   = fileAsBytes.Length
                        }).Resource;
                    }


                    var result = "";
                    var Spartan_BR_Peer_ReviewInfo = new Spartan_BR_Peer_Review
                    {
                        Key_Peer_Review       = varSpartan_BR_Peer_Review.Key_Peer_Review
                        , User_that_reviewed  = varSpartan_BR_Peer_Review.User_that_reviewed
                        , Acceptance_Criteria = varSpartan_BR_Peer_Review.Acceptance_Criteria
                        , It_worked           = varSpartan_BR_Peer_Review.It_worked
                        , Rejection_reason    = varSpartan_BR_Peer_Review.Rejection_reason
                        , Comments            = varSpartan_BR_Peer_Review.Comments
                        , Evidence            = (varSpartan_BR_Peer_Review.Evidence.HasValue && varSpartan_BR_Peer_Review.Evidence != 0) ? ((int?)Convert.ToInt32(varSpartan_BR_Peer_Review.Evidence.Value)) : null
                    };

                    result = !IsNew?
                             _ISpartan_BR_Peer_ReviewApiConsumer.Update(Spartan_BR_Peer_ReviewInfo, null, null).Resource.ToString() :
                                 _ISpartan_BR_Peer_ReviewApiConsumer.Insert(Spartan_BR_Peer_ReviewInfo, null, null).Resource.ToString();

                    return(Json(result, JsonRequestBehavior.AllowGet));
                }
                return(Json(false, JsonRequestBehavior.AllowGet));
            }
            catch (ServiceException ex)
            {
                return(Json(false, JsonRequestBehavior.AllowGet));
            }
        }
        public ActionResult Create(int Id = 0, int consult = 0)
        {
            int ModuleId   = (Session["CurrentModuleId"] != null) ? Convert.ToInt32(Session["CurrentModuleId"]) : 0;
            var permission = PermissionHelper.GetRoleObjectPermission(SessionHelper.Role, 35347);

            ViewBag.Permission = permission;
            var varSpartan_BR_Peer_Review = new Spartan_BR_Peer_ReviewModel();

            ViewBag.ObjectId  = "35347";
            ViewBag.Operation = "New";

            ViewBag.IsNew = true;



            if ((Id.GetType() == typeof(string) && Id.ToString() != "") || ((Id.GetType() == typeof(int) || Id.GetType() == typeof(Int16) || Id.GetType() == typeof(Int32) || Id.GetType() == typeof(Int64) || Id.GetType() == typeof(short)) && Id.ToString() != "0"))
            {
                ViewBag.IsNew     = false;
                ViewBag.Operation = "Update";
                if (!_tokenManager.GenerateToken())
                {
                    return(Json(null, JsonRequestBehavior.AllowGet));
                }
                _ISpartan_BR_Peer_ReviewApiConsumer.SetAuthHeader(_tokenManager.Token);
                var Spartan_BR_Peer_ReviewData = _ISpartan_BR_Peer_ReviewApiConsumer.GetByKeyComplete(Id).Resource.Spartan_BR_Peer_Reviews[0];
                if (Spartan_BR_Peer_ReviewData == null)
                {
                    return(HttpNotFound());
                }

                varSpartan_BR_Peer_Review = new Spartan_BR_Peer_ReviewModel
                {
                    Key_Peer_Review          = (int)Spartan_BR_Peer_ReviewData.Key_Peer_Review
                    , User_that_reviewed     = Spartan_BR_Peer_ReviewData.User_that_reviewed
                    , User_that_reviewedName = (string)Spartan_BR_Peer_ReviewData.User_that_reviewed_Spartan_User.Name
                    , Acceptance_Criteria    = Spartan_BR_Peer_ReviewData.Acceptance_Criteria
                    , It_worked                   = Spartan_BR_Peer_ReviewData.It_worked.GetValueOrDefault()
                    , Rejection_reason            = Spartan_BR_Peer_ReviewData.Rejection_reason
                    , Rejection_reasonDescription = (string)Spartan_BR_Peer_ReviewData.Rejection_reason_Spartan_BR_Rejection_Reason.Description
                    , Comments = Spartan_BR_Peer_ReviewData.Comments
                    , Evidence = Spartan_BR_Peer_ReviewData.Evidence
                };
                _ISpartane_FileApiConsumer.SetAuthHeader(_tokenManager.Token);
                ViewBag.EvidenceSpartane_File = _ISpartane_FileApiConsumer.GetByKey(varSpartan_BR_Peer_Review.Evidence).Resource;
            }
            if (!_tokenManager.GenerateToken())
            {
                return(Json(null, JsonRequestBehavior.AllowGet));
            }

            _ISpartan_UserApiConsumer.SetAuthHeader(_tokenManager.Token);
            var Spartan_Users_User_that_reviewed = _ISpartan_UserApiConsumer.SelAll(true);

            if (Spartan_Users_User_that_reviewed != null && Spartan_Users_User_that_reviewed.Resource != null)
            {
                ViewBag.Spartan_Users_User_that_reviewed = Spartan_Users_User_that_reviewed.Resource.OrderBy(m => m.Name).Select(m => new SelectListItem
                {
                    Text = m.Name.ToString(), Value = Convert.ToString(m.Id_User)
                }).ToList();
            }
            _ISpartan_BR_Rejection_ReasonApiConsumer.SetAuthHeader(_tokenManager.Token);
            var Spartan_BR_Rejection_Reasons_Rejection_reason = _ISpartan_BR_Rejection_ReasonApiConsumer.SelAll(true);

            if (Spartan_BR_Rejection_Reasons_Rejection_reason != null && Spartan_BR_Rejection_Reasons_Rejection_reason.Resource != null)
            {
                ViewBag.Spartan_BR_Rejection_Reasons_Rejection_reason = Spartan_BR_Rejection_Reasons_Rejection_reason.Resource.OrderBy(m => m.Description).Select(m => new SelectListItem
                {
                    Text = m.Description.ToString(), Value = Convert.ToString(m.Key_Rejection_Reason)
                }).ToList();
            }


            ViewBag.Consult = consult == 1;
            if (consult == 1)
            {
                ViewBag.Operation = "Consult";
            }
            return(View(varSpartan_BR_Peer_Review));
        }
        public ActionResult AddSpartan_BR_Peer_Review(int rowIndex = 0, int functionMode = 0, int id = 0)
        {
            int ModuleId = (Session["CurrentModuleId"] != null) ? Convert.ToInt32(Session["CurrentModuleId"]) : 0;

            ViewBag.currentRowIndex = rowIndex;
            ViewBag.functionMode    = functionMode;
            ViewBag.Consult         = false;
            var permission = PermissionHelper.GetRoleObjectPermission(SessionHelper.Role, 35347);

            ViewBag.Permission = permission;
            if (!_tokenManager.GenerateToken())
            {
                return(null);
            }
            _ISpartan_BR_Peer_ReviewApiConsumer.SetAuthHeader(_tokenManager.Token);
            Spartan_BR_Peer_ReviewModel varSpartan_BR_Peer_Review = new Spartan_BR_Peer_ReviewModel();


            if (id.ToString() != "0")
            {
                var Spartan_BR_Peer_ReviewsData = _ISpartan_BR_Peer_ReviewApiConsumer.ListaSelAll(0, 1000, "Spartan_BR_Peer_Review.Key_Peer_Review=" + id, "").Resource.Spartan_BR_Peer_Reviews;

                if (Spartan_BR_Peer_ReviewsData != null && Spartan_BR_Peer_ReviewsData.Count > 0)
                {
                    var Spartan_BR_Peer_ReviewData = Spartan_BR_Peer_ReviewsData.First();
                    varSpartan_BR_Peer_Review = new Spartan_BR_Peer_ReviewModel
                    {
                        Key_Peer_Review          = Spartan_BR_Peer_ReviewData.Key_Peer_Review
                        , User_that_reviewed     = Spartan_BR_Peer_ReviewData.User_that_reviewed
                        , User_that_reviewedName = (string)Spartan_BR_Peer_ReviewData.User_that_reviewed_Spartan_User.Name
                        , Acceptance_Criteria    = Spartan_BR_Peer_ReviewData.Acceptance_Criteria
                        , It_worked                   = Spartan_BR_Peer_ReviewData.It_worked.GetValueOrDefault()
                        , Rejection_reason            = Spartan_BR_Peer_ReviewData.Rejection_reason
                        , Rejection_reasonDescription = (string)Spartan_BR_Peer_ReviewData.Rejection_reason_Spartan_BR_Rejection_Reason.Description
                        , Comments = Spartan_BR_Peer_ReviewData.Comments
                        , Evidence = Spartan_BR_Peer_ReviewData.Evidence
                    };
                }
                _ISpartane_FileApiConsumer.SetAuthHeader(_tokenManager.Token);
                ViewBag.EvidenceSpartane_File = _ISpartane_FileApiConsumer.GetByKey(varSpartan_BR_Peer_Review.Evidence).Resource;
            }
            if (!_tokenManager.GenerateToken())
            {
                return(Json(null, JsonRequestBehavior.AllowGet));
            }

            _ISpartan_UserApiConsumer.SetAuthHeader(_tokenManager.Token);
            var Spartan_Users_User_that_reviewed = _ISpartan_UserApiConsumer.SelAll(true);

            if (Spartan_Users_User_that_reviewed != null && Spartan_Users_User_that_reviewed.Resource != null)
            {
                ViewBag.Spartan_Users_User_that_reviewed = Spartan_Users_User_that_reviewed.Resource.OrderBy(m => m.Name).Select(m => new SelectListItem
                {
                    Text = m.Name.ToString(), Value = Convert.ToString(m.Id_User)
                }).ToList();
            }
            _ISpartan_BR_Rejection_ReasonApiConsumer.SetAuthHeader(_tokenManager.Token);
            var Spartan_BR_Rejection_Reasons_Rejection_reason = _ISpartan_BR_Rejection_ReasonApiConsumer.SelAll(true);

            if (Spartan_BR_Rejection_Reasons_Rejection_reason != null && Spartan_BR_Rejection_Reasons_Rejection_reason.Resource != null)
            {
                ViewBag.Spartan_BR_Rejection_Reasons_Rejection_reason = Spartan_BR_Rejection_Reasons_Rejection_reason.Resource.OrderBy(m => m.Description).Select(m => new SelectListItem
                {
                    Text = m.Description.ToString(), Value = Convert.ToString(m.Key_Rejection_Reason)
                }).ToList();
            }


            return(PartialView("AddSpartan_BR_Peer_Review", varSpartan_BR_Peer_Review));
        }