Example #1
0
        public ActionResult Submitted(int Id, string IndexType, string UserRemark, string IsContinue)
        {
            PurchaseIndentCancelHeader pd = new PurchaseIndentCancelHeaderService(_unitOfWork).Find(Id);
            int ActivityType;

            bool BeforeSave = true;

            try
            {
                BeforeSave = PurchaseIndentCancelDocEvents.beforeHeaderSubmitEvent(this, new PurchaseEventArgs(Id), ref db);
            }
            catch (Exception ex)
            {
                string message = _exception.HandleException(ex);
                TempData["CSEXC"] += message;
                EventException     = true;
            }

            if (!BeforeSave)
            {
                TempData["CSEXC"] += "Falied validation before submit.";
            }

            if (ModelState.IsValid && BeforeSave && !EventException)
            {
                if (User.Identity.Name == pd.ModifiedBy || UserRoles.Contains("Admin"))
                {
                    pd.Status    = (int)StatusConstants.Submitted;
                    ActivityType = (int)ActivityTypeContants.Submitted;

                    //_PurchaseIndentCancelHeaderService.Update(pd);
                    //_unitOfWork.Save();
                    pd.ReviewBy    = null;
                    pd.ObjectState = Model.ObjectState.Modified;
                    db.PurchaseIndentCancelHeader.Add(pd);

                    try
                    {
                        PurchaseIndentCancelDocEvents.onHeaderSubmitEvent(this, new PurchaseEventArgs(Id), ref db);
                    }
                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        TempData["CSEXC"] += message;
                        EventException     = true;
                    }


                    try
                    {
                        if (EventException)
                        {
                            throw new Exception();
                        }

                        db.SaveChanges();
                        //_unitOfWork.Save();
                    }

                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        TempData["CSEXC"] += message;
                        return(RedirectToAction("Index", new { id = pd.DocTypeId, IndexType = IndexType }));
                    }

                    try
                    {
                        PurchaseIndentCancelDocEvents.afterHeaderSubmitEvent(this, new PurchaseEventArgs(Id), ref db);
                    }
                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        TempData["CSEXC"] += message;
                    }

                    LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                    {
                        DocTypeId    = pd.DocTypeId,
                        DocId        = pd.PurchaseIndentCancelHeaderId,
                        ActivityType = ActivityType,
                        UserRemark   = UserRemark,
                        DocNo        = pd.DocNo,
                        DocDate      = pd.DocDate,
                        DocStatus    = pd.Status,
                    }));

                    if (!string.IsNullOrEmpty(IsContinue) && IsContinue == "True")
                    {
                        int nextId = new NextPrevIdService(_unitOfWork).GetNextPrevId(Id, pd.DocTypeId, User.Identity.Name, ForActionConstants.PendingToSubmit, "Web.PurchaseIndentCancelHeaders", "PurchaseIndentCancelHeaderId", PrevNextConstants.Next);

                        if (nextId == 0)
                        {
                            var PendingtoSubmitCount = _PurchaseIndentCancelHeaderService.GetPurchaseIndentCancelPendingToSubmit(pd.DocTypeId, User.Identity.Name).Count();
                            if (PendingtoSubmitCount > 0)
                            {
                                return(RedirectToAction("Index_PendingToSubmit", new { id = pd.DocTypeId, IndexType = IndexType }));
                            }
                            else
                            {
                                return(RedirectToAction("Index", new { id = pd.DocTypeId, IndexType = IndexType }));
                            }
                        }

                        return(RedirectToAction("Detail", new { id = nextId, TransactionType = "submitContinue", IndexType = IndexType }).Success("Purchase Indent Cancel " + pd.DocNo + " submitted successfully."));
                    }

                    else
                    {
                        return(RedirectToAction("Index", new { id = pd.DocTypeId, IndexType = IndexType }).Success("Purchase Indent Cancel " + pd.DocNo + " submitted successfully."));
                    }
                }
                else
                {
                    return(RedirectToAction("Index", new { id = pd.DocTypeId, IndexType = IndexType }).Warning("Record can be submitted by user " + pd.ModifiedBy + " only."));
                }
            }

            return(RedirectToAction("Index", new { id = pd.DocTypeId, IndexType = IndexType }));
        }