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 }));
        }
Example #2
0
        public ActionResult Reviewed(int Id, string IndexType, string UserRemark, string IsContinue)
        {
            PurchaseIndentCancelHeader pd = new PurchaseIndentCancelHeaderService(_unitOfWork).Find(Id);

            bool BeforeSave = true;

            try
            {
                BeforeSave = PurchaseIndentCancelDocEvents.beforeHeaderReviewEvent(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)
            {
                pd.ReviewCount = (pd.ReviewCount ?? 0) + 1;
                pd.ReviewBy   += User.Identity.Name + ", ";
                pd.ObjectState = Model.ObjectState.Modified;
                db.PurchaseIndentCancelHeader.Add(pd);

                try
                {
                    PurchaseIndentCancelDocEvents.onHeaderReviewEvent(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 }));
                }

                try
                {
                    PurchaseIndentCancelDocEvents.afterHeaderReviewEvent(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 = (int)ActivityTypeContants.Reviewed,
                    UserRemark   = UserRemark,
                    DocNo        = pd.DocNo,
                    DocDate      = pd.DocDate,
                    DocStatus    = pd.Status,
                }));


                if (!string.IsNullOrEmpty(IsContinue) && IsContinue == "True")
                {
                    PurchaseIndentCancelHeader HEader = _PurchaseIndentCancelHeaderService.Find(Id);

                    int nextId = new NextPrevIdService(_unitOfWork).GetNextPrevId(Id, HEader.DocTypeId, User.Identity.Name, ForActionConstants.PendingToReview, "Web.PurchaseIndentCancelHeaders", "PurchaseIndentCancelHeaderId", PrevNextConstants.Next);
                    if (nextId == 0)
                    {
                        var PendingtoSubmitCount = _PurchaseIndentCancelHeaderService.GetPurchaseIndentCancelPendingToReview(HEader.DocTypeId, User.Identity.Name).Count();
                        if (PendingtoSubmitCount > 0)
                        {
                            return(RedirectToAction("Index_PendingToReview", new { id = HEader.DocTypeId, IndexType = IndexType }).Success("Record Reviewed Successfully"));
                        }
                        else
                        {
                            return(RedirectToAction("Index", new { id = HEader.DocTypeId, IndexType = IndexType }).Success("Record Reviewed Successfully"));
                        };
                    }

                    ViewBag.PendingToReview = PendingToReviewCount(Id);
                    return(RedirectToAction("Detail", new { id = nextId, transactionType = "ReviewContinue", IndexType = IndexType }).Success("Record Reviewed Successfully"));;
                }


                else
                {
                    return(RedirectToAction("Index", new { id = pd.DocTypeId, IndexType = IndexType }).Success("Record Reviewed Successfully"));
                }
            }

            return(RedirectToAction("Index", new { id = pd.DocTypeId, IndexType = IndexType }));
        }
Example #3
0
        public ActionResult Delete(ReasonViewModel vm)
        {
            bool BeforeSave = true;

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

            if (!BeforeSave)
            {
                TempData["CSEXC"] += "Failed validation before delete";
            }

            if (ModelState.IsValid && BeforeSave && !EventException)
            {
                List <LogTypeViewModel> LogList = new List <LogTypeViewModel>();

                //first find the Purchase Order Object based on the ID. (sience this object need to marked to be deleted IE. ObjectState.Deleted)
                var PurchaseIndentCancelHeader = db.PurchaseIndentCancelHeader.Find(vm.id);

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

                LogList.Add(new LogTypeViewModel
                {
                    ExObj = Mapper.Map <PurchaseIndentCancelHeader>(PurchaseIndentCancelHeader),
                });

                int doctypeid = PurchaseIndentCancelHeader.DocTypeId;

                //Then find all the Purchase Order Header Line associated with the above ProductType.
                var Line = (from p in db.PurchaseIndentCancelLine
                            where p.PurchaseIndentCancelHeaderId == vm.id
                            select p).ToList();

                //Mark ObjectState.Delete to all the Purchase Order Lines.
                foreach (var item in Line)
                {
                    LogList.Add(new LogTypeViewModel
                    {
                        ExObj = Mapper.Map <PurchaseIndentCancelLine>(item),
                    });

                    item.ObjectState = Model.ObjectState.Deleted;
                    db.PurchaseIndentCancelLine.Remove(item);

                    //new PurchaseIndentCancelLineService(_unitOfWork).Delete(item.PurchaseIndentCancelLineId);
                }

                // Now delete the Purhcase Order Header
                //new PurchaseIndentCancelHeaderService(_unitOfWork).Delete(vm.id);

                PurchaseIndentCancelHeader.ObjectState = Model.ObjectState.Deleted;
                db.PurchaseIndentCancelHeader.Remove(PurchaseIndentCancelHeader);

                XElement Modifications = new ModificationsCheckService().CheckChanges(LogList);

                //Commit the DB
                try
                {
                    if (EventException)
                    {
                        throw new Exception();
                    }

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

                catch (Exception ex)
                {
                    string message = _exception.HandleException(ex);
                    TempData["CSEXC"] += message;
                    return(PartialView("_Reason", vm));
                }

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

                LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                {
                    DocTypeId       = PurchaseIndentCancelHeader.DocTypeId,
                    DocId           = PurchaseIndentCancelHeader.PurchaseIndentCancelHeaderId,
                    ActivityType    = (int)ActivityTypeContants.Deleted,
                    UserRemark      = vm.Reason,
                    DocNo           = PurchaseIndentCancelHeader.DocNo,
                    xEModifications = Modifications,
                    DocDate         = PurchaseIndentCancelHeader.DocDate,
                    DocStatus       = PurchaseIndentCancelHeader.Status,
                }));

                return(Json(new { success = true }));
            }
            return(PartialView("_Reason", vm));
        }
Example #4
0
        public ActionResult HeaderPost(PurchaseIndentCancelHeaderViewModel svm)
        {
            #region BeforeSave
            bool BeforeSave = true;
            try
            {
                if (svm.PurchaseIndentCancelHeaderId <= 0)
                {
                    BeforeSave = PurchaseIndentCancelDocEvents.beforeHeaderSaveEvent(this, new PurchaseEventArgs(svm.PurchaseIndentCancelHeaderId, EventModeConstants.Add), ref db);
                }
                else
                {
                    BeforeSave = PurchaseIndentCancelDocEvents.beforeHeaderSaveEvent(this, new PurchaseEventArgs(svm.PurchaseIndentCancelHeaderId, EventModeConstants.Edit), ref db);
                }
            }
            catch (Exception ex)
            {
                string message = _exception.HandleException(ex);
                TempData["CSEXC"] += message;
                EventException     = true;
            }
            if (!BeforeSave)
            {
                TempData["CSEXC"] += "Failed validation before save";
            }
            #endregion

            #region DocTypeTimeLineValidation

            try
            {
                if (svm.PurchaseIndentCancelHeaderId <= 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 && BeforeSave && !EventException && (TimePlanValidation || Continue))
            {
                #region CreateRecord
                if (svm.PurchaseIndentCancelHeaderId <= 0)
                {
                    PurchaseIndentCancelHeader s = new PurchaseIndentCancelHeader();
                    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.ReasonId     = svm.ReasonId;
                    s.DivisionId   = svm.DivisionId;
                    s.ModifiedDate = DateTime.Now;
                    s.CreatedBy    = User.Identity.Name;
                    s.ModifiedBy   = User.Identity.Name;
                    s.Status       = (int)StatusConstants.Drafted;
                    //_PurchaseIndentCancelHeaderService.Create(s);
                    s.ObjectState = Model.ObjectState.Added;
                    db.PurchaseIndentCancelHeader.Add(s);

                    try
                    {
                        PurchaseIndentCancelDocEvents.onHeaderSaveEvent(this, new PurchaseEventArgs(s.PurchaseIndentCancelHeaderId, EventModeConstants.Add), 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)
                    {
                        PrepareViewBag(svm.DocTypeId);
                        string message = _exception.HandleException(ex);
                        TempData["CSEXC"] += message;
                        ViewBag.Mode       = "Add";
                        return(View("Create", svm));
                    }

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

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

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

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

                    StringBuilder logstring         = new StringBuilder();
                    PurchaseIndentCancelHeader temp = _PurchaseIndentCancelHeaderService.Find(svm.PurchaseIndentCancelHeaderId);

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


                    int status = temp.Status;

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

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

                    temp.ModifiedDate = DateTime.Now;
                    temp.ModifiedBy   = User.Identity.Name;
                    temp.ObjectState  = Model.ObjectState.Modified;
                    db.PurchaseIndentCancelHeader.Add(temp);
                    //_PurchaseIndentCancelHeaderService.Update(temp);

                    LogList.Add(new LogTypeViewModel
                    {
                        ExObj = ExRec,
                        Obj   = temp,
                    });

                    XElement Modifications = new ModificationsCheckService().CheckChanges(LogList);

                    try
                    {
                        PurchaseIndentCancelDocEvents.onHeaderSaveEvent(this, new PurchaseEventArgs(temp.PurchaseIndentCancelHeaderId, EventModeConstants.Edit), 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)
                    {
                        PrepareViewBag(svm.DocTypeId);
                        string message = _exception.HandleException(ex);
                        TempData["CSEXC"] += message;
                        ViewBag.Mode       = "Edit";
                        return(View("Create", svm));
                    }

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

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

                    return(RedirectToAction("Index", new { id = svm.DocTypeId }).Success("Data saved successfully"));
                }
                #endregion
            }
            PrepareViewBag(svm.DocTypeId);
            ViewBag.Mode = "Add";
            return(View("Create", svm));
        }
Example #5
0
        public ActionResult _ResultsPost(PurchaseIndentCancelMasterDetailModel vm)
        {
            int Serial = _PurchaseIndentCancelLineService.GetMaxSr(vm.PurchaseIndentCancelViewModels.FirstOrDefault().PurchaseIndentCancelHeaderId);

            bool BeforeSave = true;

            try
            {
                BeforeSave = PurchaseIndentCancelDocEvents.beforeLineSaveBulkEvent(this, new PurchaseEventArgs(vm.PurchaseIndentCancelViewModels.FirstOrDefault().PurchaseIndentCancelHeaderId), ref db);
            }
            catch (Exception ex)
            {
                string message = _exception.HandleException(ex);
                TempData["CSEXCL"] += message;
                EventException      = true;
            }

            if (!BeforeSave)
            {
                ModelState.AddModelError("", "Validation failed before save");
            }

            if (ModelState.IsValid && BeforeSave && !EventException)
            {
                foreach (var item in vm.PurchaseIndentCancelViewModels)
                {
                    decimal balqty = (from p in db.ViewPurchaseIndentBalance
                                      where p.PurchaseIndentLineId == item.PurchaseIndentLineId
                                      select p.BalanceQty).FirstOrDefault();
                    if (balqty < item.Qty)
                    {
                        ModelState.AddModelError("", "Qty Exceeding Balance Qty");
                        return(PartialView("_Results", vm));
                    }
                    if (item.Qty > 0)
                    {
                        PurchaseIndentCancelLine line = new PurchaseIndentCancelLine();

                        line.PurchaseIndentCancelHeaderId = item.PurchaseIndentCancelHeaderId;
                        line.PurchaseIndentLineId         = item.PurchaseIndentLineId;
                        line.Qty          = item.Qty;
                        line.CreatedDate  = DateTime.Now;
                        line.ModifiedDate = DateTime.Now;
                        line.CreatedBy    = User.Identity.Name;
                        line.ModifiedBy   = User.Identity.Name;
                        line.ObjectState  = Model.ObjectState.Added;
                        db.PurchaseIndentCancelLine.Add(line);

                        //_PurchaseIndentCancelLineService.Create(line);
                    }
                }

                PurchaseIndentCancelHeader Header = db.PurchaseIndentCancelHeader.Find(vm.PurchaseIndentCancelViewModels.FirstOrDefault().PurchaseIndentCancelHeaderId);

                if (Header.Status != (int)StatusConstants.Drafted && Header.Status != (int)StatusConstants.Import)
                {
                    Header.Status       = (int)StatusConstants.Modified;
                    Header.ModifiedBy   = User.Identity.Name;
                    Header.ModifiedDate = DateTime.Now;

                    Header.ObjectState = Model.ObjectState.Modified;
                    db.PurchaseIndentCancelHeader.Add(Header);
                }

                try
                {
                    PurchaseIndentCancelDocEvents.onLineSaveBulkEvent(this, new PurchaseEventArgs(vm.PurchaseIndentCancelViewModels.FirstOrDefault().PurchaseIndentCancelHeaderId), ref db);
                }
                catch (Exception ex)
                {
                    string message = _exception.HandleException(ex);
                    TempData["CSEXCL"] += message;
                    EventException      = true;
                }

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

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

                catch (Exception ex)
                {
                    string message = _exception.HandleException(ex);
                    TempData["CSEXCL"] += message;
                    return(PartialView("_Results", vm));
                }

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

                LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                {
                    DocTypeId    = Header.DocTypeId,
                    DocId        = Header.PurchaseIndentCancelHeaderId,
                    ActivityType = (int)ActivityTypeContants.MultipleCreate,
                    DocNo        = Header.DocNo,
                    DocDate      = Header.DocDate,
                    DocStatus    = Header.Status,
                }));

                return(Json(new { success = true }));
            }
            return(PartialView("_Results", vm));
        }
Example #6
0
        public ActionResult DeletePost(PurchaseIndentCancelLineViewModel vm)
        {
            bool BeforeSave = true;

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

            if (!BeforeSave)
            {
                TempData["CSEXC"] += "Validation failed before delete.";
            }


            if (BeforeSave && !EventException)
            {
                List <LogTypeViewModel> LogList = new List <LogTypeViewModel>();

                PurchaseIndentCancelLine IndentCancelLine = db.PurchaseIndentCancelLine.Find(vm.PurchaseIndentCancelLineId);

                try
                {
                    PurchaseIndentCancelDocEvents.onLineDeleteEvent(this, new PurchaseEventArgs(IndentCancelLine.PurchaseIndentCancelHeaderId, IndentCancelLine.PurchaseIndentCancelLineId), ref db);
                }
                catch (Exception ex)
                {
                    string message = _exception.HandleException(ex);
                    TempData["CSEXCL"] += message;
                    EventException      = true;
                }

                LogList.Add(new LogTypeViewModel
                {
                    ExObj = Mapper.Map <PurchaseIndentCancelLine>(IndentCancelLine),
                });

                IndentCancelLine.ObjectState = Model.ObjectState.Deleted;
                db.PurchaseIndentCancelLine.Remove(IndentCancelLine);

                //_PurchaseIndentCancelLineService.Delete(vm.PurchaseIndentCancelLineId);
                PurchaseIndentCancelHeader header = new PurchaseIndentCancelHeaderService(_unitOfWork).Find(IndentCancelLine.PurchaseIndentCancelHeaderId);
                if (header.Status != (int)StatusConstants.Drafted)
                {
                    header.Status = (int)StatusConstants.Modified;
                    //new PurchaseIndentCancelHeaderService(_unitOfWork).Update(header);
                    header.ModifiedBy   = User.Identity.Name;
                    header.ModifiedDate = DateTime.Now;
                    header.ObjectState  = Model.ObjectState.Modified;
                    db.PurchaseIndentCancelHeader.Add(header);
                }

                XElement Modifications = new ModificationsCheckService().CheckChanges(LogList);

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

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

                catch (Exception ex)
                {
                    string message = _exception.HandleException(ex);
                    TempData["CSEXCL"] += message;
                    return(PartialView("_Create", vm));
                }

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


                LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                {
                    DocTypeId       = header.DocTypeId,
                    DocId           = IndentCancelLine.PurchaseIndentCancelHeaderId,
                    DocLineId       = IndentCancelLine.PurchaseIndentLineId,
                    ActivityType    = (int)ActivityTypeContants.Deleted,
                    DocNo           = header.DocNo,
                    xEModifications = Modifications,
                    DocDate         = header.DocDate,
                    DocStatus       = header.Status,
                }));
            }

            return(Json(new { success = true }));
        }
Example #7
0
        public ActionResult _CreatePost(PurchaseIndentCancelLineViewModel svm)
        {
            if (svm.PurchaseIndentCancelLineId <= 0)
            {
                ViewBag.LineMode = "Create";
            }
            else
            {
                ViewBag.LineMode = "Edit";
            }

            bool BeforeSave = true;

            try
            {
                if (svm.PurchaseIndentLineId <= 0)
                {
                    BeforeSave = PurchaseIndentCancelDocEvents.beforeLineSaveEvent(this, new PurchaseEventArgs(svm.PurchaseIndentCancelHeaderId, EventModeConstants.Add), ref db);
                }
                else
                {
                    BeforeSave = PurchaseIndentCancelDocEvents.beforeLineSaveEvent(this, new PurchaseEventArgs(svm.PurchaseIndentCancelHeaderId, EventModeConstants.Edit), ref db);
                }
            }
            catch (Exception ex)
            {
                string message = _exception.HandleException(ex);
                TempData["CSEXCL"] += message;
                EventException      = true;
            }

            if (!BeforeSave)
            {
                ModelState.AddModelError("", "Validation failed before save.");
            }

            if (svm.PurchaseIndentCancelLineId <= 0)
            {
                PurchaseIndentCancelLine s = new PurchaseIndentCancelLine();
                decimal balqty             = (from p in db.ViewPurchaseIndentBalance
                                              where p.PurchaseIndentLineId == svm.PurchaseIndentLineId
                                              select p.BalanceQty).FirstOrDefault();
                if (balqty < svm.Qty)
                {
                    ModelState.AddModelError("Qty", "Qty Exceeding Balance Qty");
                }
                if (svm.Qty == 0)
                {
                    ModelState.AddModelError("Qty", "Please Check Qty");
                }
                if (svm.PurchaseIndentLineId <= 0)
                {
                    ModelState.AddModelError("PurchaseIndentLineId", "The Purchase Indent field is required");
                }
                if (ModelState.IsValid && BeforeSave && !EventException)
                {
                    s.PurchaseIndentCancelHeaderId = svm.PurchaseIndentCancelHeaderId;
                    s.PurchaseIndentLineId         = svm.PurchaseIndentLineId;
                    s.Qty          = svm.Qty;
                    s.CreatedDate  = DateTime.Now;
                    s.ModifiedDate = DateTime.Now;
                    s.Sr           = _PurchaseIndentCancelLineService.GetMaxSr(s.PurchaseIndentCancelHeaderId);
                    s.CreatedBy    = User.Identity.Name;
                    s.ModifiedBy   = User.Identity.Name;
                    //_PurchaseIndentCancelLineService.Create(s);
                    s.ObjectState = Model.ObjectState.Added;
                    db.PurchaseIndentCancelLine.Add(s);

                    PurchaseIndentCancelHeader temp2 = new PurchaseIndentCancelHeaderService(_unitOfWork).Find(s.PurchaseIndentCancelHeaderId);
                    if (temp2.Status != (int)StatusConstants.Drafted && temp2.Status != (int)StatusConstants.Import)
                    {
                        temp2.Status       = (int)StatusConstants.Modified;
                        temp2.ModifiedBy   = User.Identity.Name;
                        temp2.ModifiedDate = DateTime.Now;
                        temp2.ObjectState  = Model.ObjectState.Modified;
                        db.PurchaseIndentCancelHeader.Add(temp2);
                        //new PurchaseIndentCancelHeaderService(_unitOfWork).Update(temp2);
                    }

                    try
                    {
                        PurchaseIndentCancelDocEvents.onLineSaveEvent(this, new PurchaseEventArgs(s.PurchaseIndentCancelHeaderId, s.PurchaseIndentCancelLineId, EventModeConstants.Add), ref db);
                    }
                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        TempData["CSEXCL"] += message;
                        EventException      = true;
                    }

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

                        db.SaveChanges();
                        //_unitOfWork.Save();
                    }
                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        TempData["CSEXCL"] += message;
                        return(PartialView("_Create", svm));
                    }

                    try
                    {
                        PurchaseIndentCancelDocEvents.afterLineSaveEvent(this, new PurchaseEventArgs(s.PurchaseIndentCancelHeaderId, s.PurchaseIndentCancelLineId, EventModeConstants.Add), ref db);
                    }
                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        TempData["CSEXCL"] += message;
                    }


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


                    return(RedirectToAction("_Create", new { id = s.PurchaseIndentCancelHeaderId }));
                }
                return(PartialView("_Create", svm));
            }
            else
            {
                List <LogTypeViewModel> LogList = new List <LogTypeViewModel>();

                PurchaseIndentCancelHeader temp = new PurchaseIndentCancelHeaderService(_unitOfWork).Find(svm.PurchaseIndentCancelHeaderId);


                int           status    = temp.Status;
                StringBuilder logstring = new StringBuilder();

                PurchaseIndentCancelLine s = _PurchaseIndentCancelLineService.Find(svm.PurchaseIndentCancelLineId);

                PurchaseIndentCancelLine ExRec = new PurchaseIndentCancelLine();
                ExRec = Mapper.Map <PurchaseIndentCancelLine>(s);

                decimal balqty = (from p in db.ViewPurchaseIndentBalance
                                  where p.PurchaseIndentLineId == svm.PurchaseIndentLineId
                                  select p.BalanceQty).FirstOrDefault();
                if (balqty + s.Qty < svm.Qty)
                {
                    ModelState.AddModelError("Qty", "Qty Exceeding Balance Qty");
                }


                if (ModelState.IsValid && BeforeSave && !EventException)
                {
                    if (svm.Qty > 0)
                    {
                        s.Qty          = svm.Qty;
                        s.ModifiedBy   = User.Identity.Name;
                        s.ModifiedDate = DateTime.Now;
                    }

                    s.ObjectState = Model.ObjectState.Modified;
                    db.PurchaseIndentCancelLine.Add(s);

                    //_PurchaseIndentCancelLineService.Update(s);

                    if (temp.Status != (int)StatusConstants.Drafted && temp.Status != (int)StatusConstants.Import)
                    {
                        temp.Status = (int)StatusConstants.Modified;
                        //new PurchaseIndentCancelHeaderService(_unitOfWork).Update(temp);
                        temp.ModifiedDate = DateTime.Now;
                        temp.ModifiedBy   = User.Identity.Name;
                        temp.ObjectState  = Model.ObjectState.Modified;
                        db.PurchaseIndentCancelHeader.Add(temp);
                    }

                    LogList.Add(new LogTypeViewModel
                    {
                        ExObj = ExRec,
                        Obj   = s,
                    });

                    XElement Modifications = new ModificationsCheckService().CheckChanges(LogList);

                    try
                    {
                        PurchaseIndentCancelDocEvents.onLineSaveEvent(this, new PurchaseEventArgs(s.PurchaseIndentCancelHeaderId, s.PurchaseIndentCancelLineId, EventModeConstants.Edit), ref db);
                    }
                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        TempData["CSEXCL"] += message;
                        EventException      = true;
                    }

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

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

                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        TempData["CSEXCL"] += message;
                        return(PartialView("_Create", svm));
                    }

                    try
                    {
                        PurchaseIndentCancelDocEvents.afterLineSaveEvent(this, new PurchaseEventArgs(s.PurchaseIndentCancelHeaderId, s.PurchaseIndentCancelLineId, EventModeConstants.Edit), ref db);
                    }
                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        TempData["CSEXC"] += message;
                    }


                    //SAving the Activity Log::

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

                    return(Json(new { success = true }));
                }
                return(PartialView("_Create", svm));
            }
        }