public ActionResult Detail(int id, string transactionType, string IndexType)
        {
            ViewBag.transactionType = transactionType;
            ViewBag.IndexStatus     = IndexType;

            ProdOrderCancelHeader          s   = _ProdOrderCancelHeaderService.Find(id);
            ProdOrderCancelHeaderViewModel svm = Mapper.Map <ProdOrderCancelHeader, ProdOrderCancelHeaderViewModel>(s);

            PrepareViewBag(s.DocTypeId);
            if (s == null)
            {
                return(HttpNotFound());
            }

            if (String.IsNullOrEmpty(transactionType) || transactionType == "detail")
            {
                LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                {
                    DocTypeId    = s.DocTypeId,
                    DocId        = s.ProdOrderCancelHeaderId,
                    ActivityType = (int)ActivityTypeContants.Detail,
                    DocNo        = s.DocNo,
                    DocDate      = s.DocDate,
                    DocStatus    = s.Status,
                }));
            }

            return(View("Create", svm));
        }
        // GET: /ProdOrderCancelHeader/Create

        public ActionResult Create(int id)//DocTypeId
        {
            PrepareViewBag(id);
            ProdOrderCancelHeaderViewModel s = new ProdOrderCancelHeaderViewModel();

            s.DivisionId  = (int)System.Web.HttpContext.Current.Session["DivisionId"];
            s.SiteId      = (int)System.Web.HttpContext.Current.Session["SiteId"];
            s.DocDate     = DateTime.Now;
            s.DocTypeId   = id;
            s.CreatedDate = DateTime.Now;

            //Getting Settings
            var settings = new ProdOrderSettingsService(_unitOfWork).GetProdOrderSettingsForDocument(id, s.DivisionId, s.SiteId);

            if (settings == null && UserRoles.Contains("SysAdmin"))
            {
                return(RedirectToAction("CreateForCancel", "ProdOrderSettings", new { id = id }).Warning("Please create job order cancel settings"));
            }
            else if (settings == null && !UserRoles.Contains("SysAdmin"))
            {
                return(View("~/Views/Shared/InValidSettings.cshtml"));
            }

            if (new RolePermissionService(_unitOfWork).IsActionAllowed(UserRoles, id, null, this.ControllerContext.RouteData.Values["controller"].ToString(), "Create") == false)
            {
                return(View("~/Views/Shared/PermissionDenied.cshtml").Warning("You don't have permission to do this task."));
            }


            s.DocNo      = new DocumentTypeService(_unitOfWork).FGetNewDocNo("DocNo", ConfigurationManager.AppSettings["DataBaseSchema"] + ".ProdOrderCancelHeaders", s.DocTypeId, s.DocDate, s.DivisionId, s.SiteId);
            ViewBag.Mode = "Add";
            return(View("Create", s));
        }
        // GET: /ProdOrderCancelHeader/Edit/5
        private ActionResult Edit(int id, string IndexType)
        {
            ViewBag.IndexStatus = IndexType;

            ProdOrderCancelHeader          s   = _ProdOrderCancelHeaderService.Find(id);
            ProdOrderCancelHeaderViewModel svm = Mapper.Map <ProdOrderCancelHeader, ProdOrderCancelHeaderViewModel>(s);

            if (svm == null)
            {
                return(HttpNotFound());
            }

            if (new RolePermissionService(_unitOfWork).IsActionAllowed(UserRoles, s.DocTypeId, null, this.ControllerContext.RouteData.Values["controller"].ToString(), "Edit") == false)
            {
                return(View("~/Views/Shared/PermissionDenied.cshtml").Warning("You don't have permission to do this task."));
            }

            #region DocTypeTimeLineValidation
            try
            {
                TimePlanValidation = DocumentValidation.ValidateDocument(Mapper.Map <DocumentUniqueId>(s), DocumentTimePlanTypeConstants.Modify, User.Identity.Name, out ExceptionMsg, out Continue);
            }
            catch (Exception ex)
            {
                string message = _exception.HandleException(ex);
                TempData["CSEXC"] += message;
                TimePlanValidation = false;
            }

            if (!TimePlanValidation)
            {
                TempData["CSEXC"] += ExceptionMsg;
            }
            #endregion

            if ((!TimePlanValidation && !Continue))
            {
                return(RedirectToAction("DetailInformation", new { id = id, IndexType = IndexType }));
            }
            //Getting Settings
            var settings = new ProdOrderSettingsService(_unitOfWork).GetProdOrderSettingsForDocument(s.DocTypeId, s.DivisionId, s.SiteId);
            if (settings == null && UserRoles.Contains("SysAdmin"))
            {
                return(RedirectToAction("CreateForCancel", "ProdOrderSettings", new { id = s.DocTypeId }).Warning("Please create Prod Order cancel settings"));
            }
            else if (settings == null && !UserRoles.Contains("SysAdmin"))
            {
                return(View("~/Views/Shared/InValidSettings.cshtml"));
            }
            PrepareViewBag(s.DocTypeId);
            ViewBag.Mode = "Edit";


            if (!(System.Web.HttpContext.Current.Request.UrlReferrer.PathAndQuery).Contains("Create"))
            {
                LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                {
                    DocTypeId    = s.DocTypeId,
                    DocId        = s.ProdOrderCancelHeaderId,
                    ActivityType = (int)ActivityTypeContants.Detail,
                    DocNo        = s.DocNo,
                    DocDate      = s.DocDate,
                    DocStatus    = s.Status,
                }));
            }


            return(View("Create", svm));
        }
        public ActionResult HeaderPost(ProdOrderCancelHeaderViewModel svm)
        {
            #region DocTypeTimeLineValidation

            try
            {
                if (svm.ProdOrderCancelHeaderId <= 0)
                {
                    TimePlanValidation = DocumentValidation.ValidateDocument(Mapper.Map <DocumentUniqueId>(svm), DocumentTimePlanTypeConstants.Create, User.Identity.Name, out ExceptionMsg, out Continue);
                }
                else
                {
                    TimePlanValidation = DocumentValidation.ValidateDocument(Mapper.Map <DocumentUniqueId>(svm), DocumentTimePlanTypeConstants.Modify, User.Identity.Name, out ExceptionMsg, out Continue);
                }
            }
            catch (Exception ex)
            {
                string message = _exception.HandleException(ex);
                TempData["CSEXC"] += message;
                TimePlanValidation = false;
            }

            if (!TimePlanValidation)
            {
                TempData["CSEXC"] += ExceptionMsg;
            }

            #endregion

            if (ModelState.IsValid && (TimePlanValidation || Continue))
            {
                #region CreateRecord
                if (svm.ProdOrderCancelHeaderId <= 0)
                {
                    ProdOrderCancelHeader s = new ProdOrderCancelHeader();
                    s.DocTypeId    = svm.DocTypeId;
                    s.DocDate      = svm.DocDate;
                    s.DocNo        = svm.DocNo;
                    s.Remark       = svm.Remark;
                    s.CreatedDate  = DateTime.Now;
                    s.SiteId       = svm.SiteId;
                    s.DivisionId   = svm.DivisionId;
                    s.ModifiedDate = DateTime.Now;
                    s.CreatedBy    = User.Identity.Name;
                    s.ModifiedBy   = User.Identity.Name;
                    s.Status       = (int)StatusConstants.Drafted;
                    _ProdOrderCancelHeaderService.Create(s);

                    try
                    {
                        _unitOfWork.Save();
                    }

                    catch (Exception ex)
                    {
                        PrepareViewBag(s.DocTypeId);
                        string message = _exception.HandleException(ex);
                        TempData["CSEXC"] += message;
                        ViewBag.Mode       = "Add";
                        return(View("Create", svm));
                    }

                    LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                    {
                        DocTypeId    = s.DocTypeId,
                        DocId        = s.ProdOrderCancelHeaderId,
                        ActivityType = (int)ActivityTypeContants.Added,
                        DocNo        = s.DocNo,
                        DocDate      = s.DocDate,
                        DocStatus    = s.Status,
                    }));

                    return(RedirectToAction("Modify", new { id = s.ProdOrderCancelHeaderId }).Success("Data saved Successfully"));
                }
                #endregion

                #region EditRecord
                else
                {
                    List <LogTypeViewModel> LogList = new List <LogTypeViewModel>();


                    StringBuilder         logstring = new StringBuilder();
                    ProdOrderCancelHeader temp      = _ProdOrderCancelHeaderService.Find(svm.ProdOrderCancelHeaderId);

                    ProdOrderCancelHeader ExRec = new ProdOrderCancelHeader();
                    ExRec = Mapper.Map <ProdOrderCancelHeader>(temp);

                    int status = temp.Status;

                    if (temp.Status != (int)StatusConstants.Drafted && temp.Status != (int)StatusConstants.Import)
                    {
                        temp.Status = (int)StatusConstants.Modified;
                    }

                    temp.DocDate = svm.DocDate;
                    temp.DocNo   = svm.DocNo;
                    temp.Remark  = svm.Remark;

                    temp.ModifiedDate = DateTime.Now;
                    temp.ModifiedBy   = User.Identity.Name;
                    _ProdOrderCancelHeaderService.Update(temp);

                    LogList.Add(new LogTypeViewModel
                    {
                        ExObj = ExRec,
                        Obj   = temp,
                    });
                    XElement Modifications = new ModificationsCheckService().CheckChanges(LogList);
                    try
                    {
                        _unitOfWork.Save();
                    }

                    catch (Exception ex)
                    {
                        PrepareViewBag(temp.DocTypeId);
                        string message = _exception.HandleException(ex);
                        TempData["CSEXC"] += message;
                        ViewBag.Mode       = "Edit";
                        return(View("Create", svm));
                    }

                    LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                    {
                        DocTypeId       = temp.DocTypeId,
                        DocId           = temp.ProdOrderCancelHeaderId,
                        ActivityType    = (int)ActivityTypeContants.Modified,
                        DocNo           = temp.DocNo,
                        xEModifications = Modifications,
                        DocDate         = temp.DocDate,
                        DocStatus       = temp.Status,
                    }));

                    return(RedirectToAction("Index", new { id = temp.DocTypeId, IndexType = "" }).Success("Data saved successfully"));
                }

                #endregion
            }
            PrepareViewBag(svm.DocTypeId);
            ViewBag.Mode = "Add";
            return(View("Create", svm));
        }