public ActionResult NcrGridViewNew(NcrCreateViewModel ncrVM)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    if (ncrVM != null)
                    {
                        HseqCaseFile hseqCaseFile;
                        Ncr          ncr = new Ncr();
                        Mapper.Map(ncrVM, ncr);

                        ncr = (Ncr)_RecordService.CreateCaseFile(ncr, out hseqCaseFile, db);

                        db.HseqRecords.Add(ncr);
                        db.SaveChanges();

                        //create the folder in Alfresco and return the alfresconoderef
                        //Dummy for now

                        //int alfresconoderef = caseNo;
                        //hseqCaseFile.AlfrescoNoderef = caseNo;

                        //car.AlfrescoNoderef = caseNo;
                    }
                }
                catch (Exception e)
                {
                    ViewData["EditError"] = e.Message;
                    return(PartialView("_NcrNewView", ncrVM));
                }
            }
            else
            {
                var errors = ModelState.Values.SelectMany(v => v.Errors);
                Console.WriteLine(errors);
                ViewData["EditError"] = "Please, correct all errors.";
                return(PartialView("_NcrNewView", ncrVM));
            }
            return(PartialView("_MainContentCallbackPanel"));
        }
        public ActionResult MainContentCallbackPanel()

        // DXCOMMENT: Pass a data model for GridView in the PartialView method's second parameter
        {
            if (DevExpressHelper.IsCallback)
            {
                NavigationFilter.RecordTypeCheckState      = null;
                NavigationFilter.ResponsibleAreaCheckState = null;
                NavigationFilter.CoordinatorsCheckState    = null;

                NavigationFilter.RecordTypes        = null;
                NavigationFilter.ResponsibleAreaIds = null;
                NavigationFilter.CoordinatorIds     = null;

                //Checked, Unchecked, Indeterminate

                NavigationFilter.RecordTypeCheckState      = Request.Params["recordTypeCheckState"];
                NavigationFilter.ResponsibleAreaCheckState = Request.Params["responsibleAreaCheckState"];
                NavigationFilter.CoordinatorsCheckState    = Request.Params["coordinatorsCheckState"];

                //Record Type
                if (!string.IsNullOrEmpty(Request.Params["recordTypeCheckedNodes"]))
                {
                    string recordTypeNodes = Request.Params["recordTypeCheckedNodes"];

                    NavigationFilter.RecordTypes = recordTypeNodes.Split(',');

                    setActiveTab();
                }

                //Responsible Area Type
                if (!string.IsNullOrEmpty(Request.Params["responsibleAreaCheckedNodes"]))
                {
                    string responsibleAreaNodes = Request.Params["responsibleAreaCheckedNodes"];

                    NavigationFilter.ResponsibleAreaIds = Array.ConvertAll(responsibleAreaNodes.Split(','), int.Parse);
                }

                if (!string.IsNullOrEmpty(Request.Params["coordinatorsCheckedNodes"]))
                {
                    string responsibleAreaNodes = Request.Params["coordinatorsCheckedNodes"];

                    NavigationFilter.CoordinatorIds = Array.ConvertAll(responsibleAreaNodes.Split(','), int.Parse);
                }

                //ViewData["Collapsed"] = false;

                //edit
                if (!string.IsNullOrEmpty(Request.Params["EditRecord"]))
                {
                    if (!string.IsNullOrEmpty(Request.Params["currentActiveView"]) && !string.IsNullOrEmpty(Request.Params["recordId"]))
                    {
                        string currentActiveView = Request.Params["currentActiveView"];
                        int    recordId          = int.Parse(Request.Params["recordId"]);

                        if (currentActiveView.Contains("Task"))
                        {
                            HseqTask record = db.HseqTasks.Find(recordId);
                            HseqTaskEditViewModel HseqTaskEditVM = Mapper.Map <HseqTask, HseqTaskEditViewModel>(record);

                            ViewData["record"]      = HseqTaskEditVM;
                            ViewData["currentview"] = "_Task" + EDIT_VIEW_PREFIX;
                        }
                        else if (currentActiveView.Contains("Approval"))
                        {
                            HseqApprovalRequest       record             = db.HseqApprovalRequests.Find(recordId);
                            HseqApprovalEditViewModel HseqApprovalEditVM = Mapper.Map <HseqApprovalRequest, HseqApprovalEditViewModel>(record);

                            ViewData["record"]      = HseqApprovalEditVM;
                            ViewData["currentview"] = "_Approval" + EDIT_VIEW_PREFIX;
                        }

                        ////////////////////////////////////////

                        else if (currentActiveView.Contains("Ncr"))
                        {
                            Ncr record = db.NcrRecords.Find(recordId);
                            NcrEditViewModel ncrEditVM = Mapper.Map <Ncr, NcrEditViewModel>(record);

                            ViewData["record"]      = ncrEditVM;
                            ViewData["currentview"] = "_Ncr" + EDIT_VIEW_PREFIX;
                        }
                        else if (currentActiveView.Contains("Car"))
                        {
                            Car record = db.CarRecords.Find(recordId);
                            CarEditViewModel carEditVM = Mapper.Map <Car, CarEditViewModel>(record);

                            ViewData["record"]      = carEditVM;
                            ViewData["currentview"] = "_Car" + EDIT_VIEW_PREFIX;
                        }
                        else if (currentActiveView.Contains("Par"))
                        {
                            Par record = db.ParRecords.Find(recordId);
                            ParEditViewModel parEditVM = Mapper.Map <Par, ParEditViewModel>(record);

                            ViewData["record"]      = parEditVM;
                            ViewData["currentview"] = "_Par" + EDIT_VIEW_PREFIX;
                        }
                        else if (currentActiveView.Contains("Fis"))
                        {
                            Fis record = db.FisRecords.Find(recordId);
                            FisEditViewModel fisEditVM = Mapper.Map <Fis, FisEditViewModel>(record);

                            ViewData["record"]      = fisEditVM;
                            ViewData["currentview"] = "_Fis" + EDIT_VIEW_PREFIX;
                        }
                    }
                }

                //new
                else if (!string.IsNullOrEmpty(Request.Params["NewRecord"]))
                {
                    if (!string.IsNullOrEmpty(Request.Params["currentActiveView"]))
                    {
                        string currentActiveView = Request.Params["currentActiveView"];

                        if (currentActiveView.Contains("Ncr"))
                        {
                            Ncr ncr = new Ncr();
                            ncr.CaseNo      = _RecordService.GetNextCaseNumber(db);
                            ncr.RecordNo    = ncr.CaseNo;
                            ncr.CreatedBy   = _RecordService.GetCurrentApplicationUser().FullName;
                            ncr.DateCreated = DateTime.Now;
                            ncr.RecordType  = RecordType.NCR;
                            ncr.NcrSource   = NcrSource.Internal;
                            ncr.NcrState    = NcrState.New;

                            NcrCreateViewModel carVM = Mapper.Map <Ncr, NcrCreateViewModel>(ncr);

                            ViewData["record"]      = carVM;
                            ViewData["currentview"] = "_Ncr" + NEW_VIEW_PREFIX;
                        }
                        else if (currentActiveView.Contains("Car"))
                        {
                            Car car = new Car();
                            car.CaseNo      = _RecordService.GetNextCaseNumber(db);
                            car.RecordNo    = car.CaseNo;
                            car.CreatedBy   = _RecordService.GetCurrentApplicationUser().FullName;
                            car.DateCreated = DateTime.Now;
                            car.RecordType  = RecordType.CAR;

                            CarCreateViewModel carVM = Mapper.Map <Car, CarCreateViewModel>(car);

                            ViewData["record"]      = carVM;
                            ViewData["currentview"] = "_Car" + NEW_VIEW_PREFIX;
                        }
                        else if (currentActiveView.Contains("Par"))
                        {
                            Par par = new Par();
                            par.CaseNo      = _RecordService.GetNextCaseNumber(db);
                            par.RecordNo    = par.CaseNo;
                            par.CreatedBy   = _RecordService.GetCurrentApplicationUser().FullName;
                            par.DateCreated = DateTime.Now;
                            par.RecordType  = RecordType.PAR;

                            ParCreateViewModel parVM = Mapper.Map <Par, ParCreateViewModel>(par);

                            ViewData["record"]      = parVM;
                            ViewData["currentview"] = "_Par" + NEW_VIEW_PREFIX;
                        }
                        else if (currentActiveView.Contains("Fis"))
                        {
                            Fis fis = new Fis();
                            fis.CaseNo      = _RecordService.GetNextCaseNumber(db);
                            fis.RecordNo    = fis.CaseNo;
                            fis.CreatedBy   = _RecordService.GetCurrentApplicationUser().FullName;
                            fis.DateCreated = DateTime.Now;
                            fis.RecordType  = RecordType.FIS;

                            FisCreateViewModel fisVM = Mapper.Map <Fis, FisCreateViewModel>(fis);

                            ViewData["record"]      = fisVM;
                            ViewData["currentview"] = "_Fis" + NEW_VIEW_PREFIX;
                        }
                    }
                }

                //// Task ///////////////////
                else if (!string.IsNullOrEmpty(Request.Params["addTask"]))
                {
                    if (!string.IsNullOrEmpty(Request.Params["currentActiveView"]) && !string.IsNullOrEmpty(Request.Params["recordId"]))
                    {
                        string currentActiveView = Request.Params["currentActiveView"];
                        int    recordId          = int.Parse(Request.Params["recordId"]);

                        HseqTask hseqTask = new HseqTask()
                        {
                            Status = TaskStatus.NotStarted
                        };

                        HseqRecord hseqRecord = db.HseqRecords.Find(recordId);
                        hseqTask.HseqRecordID = hseqRecord.HseqRecordID;
                        hseqTask.HseqRecord   = hseqRecord;

                        HseqTaskCreateViewModel hseqTaskVM = Mapper.Map <HseqTask, HseqTaskCreateViewModel>(hseqTask);

                        ViewData["record"]      = hseqTaskVM;
                        ViewData["currentview"] = "_Task" + NEW_VIEW_PREFIX;
                    }
                }

                //// Approval ///////////////////
                else if (!string.IsNullOrEmpty(Request.Params["addApproval"]))
                {
                    if (!string.IsNullOrEmpty(Request.Params["currentActiveView"]) && !string.IsNullOrEmpty(Request.Params["recordId"]))
                    {
                        string currentActiveView = Request.Params["currentActiveView"];
                        int    recordId          = int.Parse(Request.Params["recordId"]);

                        HseqApprovalRequest hseqApproval = new HseqApprovalRequest()
                        {
                            Response     = ApprovalResult.Waiting,
                            Status       = ApprovalStatus.Active,
                            DateAssigned = DateTime.Now
                        };

                        HseqRecord hseqRecord = db.HseqRecords.Find(recordId);
                        hseqApproval.HseqRecordID = hseqRecord.HseqRecordID;
                        hseqApproval.HseqRecord   = hseqRecord;

                        HseqApprovalCreateViewModel hseqApprovalVM = Mapper.Map <HseqApprovalRequest, HseqApprovalCreateViewModel>(hseqApproval);

                        ViewData["record"]      = hseqApprovalVM;
                        ViewData["currentview"] = "_Approval" + NEW_VIEW_PREFIX;
                    }
                }

                //// Linked Record ///////////////////
                else if (!string.IsNullOrEmpty(Request.Params["createLinkedRecord"]) &&
                         !string.IsNullOrEmpty(Request.Params["linkedRecordDetails"]))
                {
                    if (!string.IsNullOrEmpty(Request.Params["recordId"]))
                    {
                        int recordId = int.Parse(Request.Params["recordId"]);

                        var linkedRecordDetails = Request.Params["linkedRecordDetails"].Split('-');
                        var sourceRecord        = linkedRecordDetails[0];
                        var targetRecord        = linkedRecordDetails[1];

                        //Ncr to Car
                        if (sourceRecord == "NCR")
                        {
                            if (targetRecord == "CAR")
                            {
                                Ncr ncr = db.NcrRecords.Find(recordId);
                                Car car = new Car(ncr)
                                {
                                    CreatedBy   = _RecordService.GetCurrentApplicationUser().FullName,
                                    DateCreated = DateTime.Now,
                                    RecordType  = RecordType.CAR
                                };

                                CarVM carVM = new CarVM()
                                {
                                    Car            = car,
                                    LinkedRecord   = true,
                                    SourceRecordId = ncr.HseqRecordID
                                };

                                ViewData["record"]      = carVM;
                                ViewData["currentview"] = "_Car" + LINKED_VIEW_PREFIX;
                            }
                        }
                    }
                }

                else
                {
                    ViewData["currentview"] = "_MainContentTabPanel";
                }
            }

            return(PartialView("_MainContentCallbackPanel"));
        }