private ActionResult Remove(int id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            DiscountType DiscountType = _DiscountTypeService.Find(id);

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



            ReasonViewModel rvm = new ReasonViewModel()
            {
                id = id,
            };

            return(PartialView("_Reason", rvm));
        }
        // GET: /PurchaseOrderHeader/Delete/5

        public ActionResult Remove(int id)
        {
            ProdOrderCancelHeader ProdOrderCancelHeader = _ProdOrderCancelHeaderService.Find(id);

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

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

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

            if (!TimePlanValidation && !Continue)
            {
                return(PartialView("AjaxError"));
            }
            #endregion

            ReasonViewModel rvm = new ReasonViewModel()
            {
                id = id,
            };
            return(PartialView("_Reason", rvm));
        }
        public ActionResult DeleteConfirmed(ReasonViewModel vm)
        {
            List <LogTypeViewModel> LogList = new List <LogTypeViewModel>();

            if (ModelState.IsValid)
            {
                var temp = _ProductCategoryProcessSettingsService.Find(vm.id);

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

                _ProductCategoryProcessSettingsService.Delete(vm.id);
                XElement Modifications = new ModificationsCheckService().CheckChanges(LogList);
                try
                {
                    _unitOfWork.Save();
                }

                catch (Exception ex)
                {
                    string message = _exception.HandleException(ex);
                    ModelState.AddModelError("", message);
                    return(PartialView("_Reason", vm));
                }

                LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                {
                    DocId           = vm.id,
                    ActivityType    = (int)ActivityTypeContants.Deleted,
                    UserRemark      = vm.Reason,
                    xEModifications = Modifications,
                }));

                return(Json(new { success = true }));
            }
            return(PartialView("_Reason", vm));
        }
        // GET: /PurchaseOrderHeader/Delete/5

        private ActionResult Remove(int id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            DispatchWaybillHeader DispatchWaybillHeader = _DispatchWaybillHeaderService.Find(id);

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

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

            if (!TimePlanValidation && !Continue)
            {
                return(PartialView("AjaxError"));
            }
            #endregion

            ReasonViewModel rvm = new ReasonViewModel()
            {
                id = id,
            };
            return(PartialView("_Reason", rvm));
        }
Пример #5
0
        public ActionResult DeleteConfirmed(ReasonViewModel vm)
        {
            if (ModelState.IsValid)
            {
                var         temp = _ProductUidService.Find(vm.id);
                ActivityLog al   = new ActivityLog()
                {
                    ActivityType = (int)ActivityTypeContants.Deleted,
                    CreatedBy    = User.Identity.Name,
                    CreatedDate  = DateTime.Now,
                    DocId        = vm.id,
                    UserRemark   = vm.Reason,
                    Narration    = "Delivery terms is deleted with Name:" + temp.ProductUidName,
                    DocTypeId    = new DocumentTypeService(_unitOfWork).FindByName(TransactionDocCategoryConstants.SaleOrder).DocumentTypeId,
                    UploadDate   = DateTime.Now,
                };
                new ActivityLogService(_unitOfWork).Create(al);


                _ProductUidService.Delete(vm.id);

                try
                {
                    _unitOfWork.Save();
                }

                catch (Exception ex)
                {
                    string message = _exception.HandleException(ex);
                    ModelState.AddModelError("", message);
                    return(PartialView("_Reason", vm));
                }


                return(Json(new { success = true }));
            }
            return(PartialView("_Reason", vm));
        }
Пример #6
0
        public IActionResult Reason(ReasonViewModel viewModel)
        {
            var amendment = GetAmendment();

            if (ModelState.IsValid)
            {
                var subReasons = _pupilService
                                 .GetAmendmentReasons(AmendmentType.RemovePupil)
                                 .Where(x => x.ParentReasonId == viewModel.SelectedReasonCode.Value);

                if (subReasons != null && subReasons.Any())
                {
                    viewModel.IsSubReason = true;
                    return(RedirectToAction("Subreason", viewModel));
                }

                amendment.AmendmentDetail.AddField(Constants.RemovePupil.FIELD_ReasonCode, viewModel.SelectedReasonCode.Value);
                amendment.InclusionReasonId = viewModel.SelectedReasonCode.Value;

                amendment.EvidenceStatus = EvidenceStatus.NotRequired;

                SaveAmendment(amendment);

                return(RedirectToAction("Prompt", "Questions"));
            }

            var parentReasonCode = viewModel.IsSubReason ? 19 : 0;

            viewModel.Reasons = _pupilService
                                .GetAmendmentReasons(AmendmentType.RemovePupil)
                                .Where(x => x.ParentReasonId == parentReasonCode).ToList();

            viewModel.PupilDetails = new PupilViewModel(amendment.Pupil);

            return(View(viewModel));
        }
Пример #7
0
        public JsonResult CreateEdit(ReasonViewModel reason)
        {
            reason.CreatedBy = Convert.ToInt32(Session["UserLoginId"]);
            reason.UpdatedBy = Convert.ToInt32(Session["UserLoginId"]);
            Mst_Reason tblReason = new Mst_Reason();

            try
            {
                if (reason.ID <= 0)
                {
                    var data = dd._context.Mst_Reason.Where(u => u.Re_Desc == reason.ReasonName).Select(x => x.Re_Desc).FirstOrDefault();
                    if (data != null)
                    {
                        ModelState.AddModelError("Reason", "Reason Already Exists");
                        return(Json(reason));
                    }
                    tblReason.Re_RecordCreated   = DateTime.Now;
                    tblReason.Re_RecordCreatedBy = reason.CreatedBy;
                    dd._context.Mst_Reason.Add(tblReason);
                }
                else
                {
                    tblReason = dd._context.Mst_Reason.Where(x => x.Re_No == reason.ID).FirstOrDefault();
                }
                tblReason.Re_Desc            = reason.ReasonName;
                tblReason.Re_Status          = reason.Status;
                tblReason.Re_RecordUpdated   = DateTime.Now;
                tblReason.Re_RecordUpdatedBy = reason.UpdatedBy;
                dd._context.SaveChanges();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            return(Json(reason));
        }
        public ActionResult DeleteConfirmed(ReasonViewModel vm)
        {
            if (ModelState.IsValid)
            {
                List <LogTypeViewModel> LogList = new List <LogTypeViewModel>();

                db.Configuration.AutoDetectChangesEnabled = false;
                var temp = _MaterialPlanCancelHeaderService.Find(vm.id);

                int status = temp.Status;

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

                var MaterialPlanCancelline = new MaterialPlanCancelLineService(_unitOfWork).GetMaterialPlanCancelForDelete(vm.id).ToList();

                List <ProdOrderCancelLine>      ProdOrderCancelLines      = new List <ProdOrderCancelLine>();
                List <PurchaseIndentCancelLine> PurchaseIndentCancelLines = new List <PurchaseIndentCancelLine>();


                foreach (var item in MaterialPlanCancelline)
                {
                    //Deleting MaterialPlanCancelforSaleOrder
                    var MaterialPlanCancelForSaleOrder = new MaterialPlanCancelForSaleOrderService(_unitOfWork).GetMaterialPlanCancelForSaleOrderForMaterialPlanCancelline(item.MaterialPlanCancelLineId).ToList();
                    foreach (var item2 in MaterialPlanCancelForSaleOrder)
                    {
                        LogList.Add(new LogTypeViewModel
                        {
                            ExObj = item2,
                        });

                        item2.ObjectState = Model.ObjectState.Deleted;
                        //new MaterialPlanCancelForSaleOrderService(_unitOfWork).Delete(item2);
                        db.MaterialPlanCancelForSaleOrder.Attach(item2);
                        db.MaterialPlanCancelForSaleOrder.Remove(item2);
                    }

                    //Deleting MaterialPlanCancelForProdOrderLine
                    var MaterialPlanCancelForProdOrderLine = new MaterialPlanCancelForProdOrderLineService(_unitOfWork).GetMaterialPlanCancelForProdORderForMaterialPlanCancel(item.MaterialPlanCancelLineId).ToList();
                    foreach (var item2 in MaterialPlanCancelForProdOrderLine)
                    {
                        LogList.Add(new LogTypeViewModel
                        {
                            ExObj = item2,
                        });

                        item2.ObjectState = Model.ObjectState.Deleted;
                        //new MaterialPlanCancelForProdOrderLineService(_unitOfWork).Delete(item2.MaterialPlanCancelForProdOrderLineId);
                        db.MaterialPlanCancelForProdOrderLine.Attach(item2);
                        db.MaterialPlanCancelForProdOrderLine.Remove(item2);
                    }

                    //new MaterialPlanCancelLineService(_unitOfWork).Delete(item.MaterialPlanCancelLineId);

                    //MaterialPlanCancelLine Si = (MaterialPlanCancelLine) item;



                    ProdOrderCancelLines = new ProdOrderCancelLineService(_unitOfWork).GetProdOrderCancelLineForMaterialPlanCancel(item.MaterialPlanCancelLineId).ToList();

                    foreach (var item2 in ProdOrderCancelLines)
                    {
                        LogList.Add(new LogTypeViewModel
                        {
                            ExObj = item2,
                        });

                        item2.ObjectState = Model.ObjectState.Deleted;
                        db.ProdOrderCancelLine.Attach(item2);
                        db.ProdOrderCancelLine.Remove(item2);
                    }

                    PurchaseIndentCancelLines = new PurchaseIndentCancelLineService(_unitOfWork).GetPurchaseIndentCancelLineForMaterialPlanCancel(item.MaterialPlanCancelLineId).ToList();

                    foreach (var item2 in PurchaseIndentCancelLines)
                    {
                        LogList.Add(new LogTypeViewModel
                        {
                            ExObj = item2,
                        });

                        item2.ObjectState = Model.ObjectState.Deleted;
                        db.PurchaseIndentCancelLine.Attach(item2);
                        db.PurchaseIndentCancelLine.Remove(item2);
                    }



                    MaterialPlanCancelLine MPL = new MaterialPlanCancelLineService(_unitOfWork).Find(item.MaterialPlanCancelLineId);

                    LogList.Add(new LogTypeViewModel
                    {
                        ExObj = MPL,
                    });

                    MPL.ObjectState = Model.ObjectState.Deleted;

                    db.MaterialPlanCancelLine.Attach(MPL);
                    db.MaterialPlanCancelLine.Remove(MPL);
                }

                //Deleting MaterialPlanCancelForProdORder
                var MaterialPlanCancelForProdOrder = new MaterialPlanCancelForProdOrderService(_unitOfWork).GetMaterialPlanCancelForProdORderForMaterialPlanCancel(vm.id).ToList();
                foreach (var item2 in MaterialPlanCancelForProdOrder)
                {
                    LogList.Add(new LogTypeViewModel
                    {
                        ExObj = item2,
                    });

                    item2.ObjectState = Model.ObjectState.Deleted;
                    //new MaterialPlanCancelForProdOrderService(_unitOfWork).Delete(item2);
                    db.MaterialPlanCancelForProdOrder.Attach(item2);
                    db.MaterialPlanCancelForProdOrder.Remove(item2);
                }



                ProdOrderCancelHeader ProdOrderCancelHeaders = new ProdOrderCancelHeaderService(_unitOfWork).GetProdOrderCancelForMaterialPlan(vm.id);


                LogList.Add(new LogTypeViewModel
                {
                    ExObj = ProdOrderCancelHeaders,
                });

                ProdOrderCancelHeaders.ObjectState = Model.ObjectState.Deleted;
                // new ProdOrderHeaderService(_unitOfWork).Delete(item2.ProdOrderHeaderId);
                db.ProdOrderCancelHeader.Attach(ProdOrderCancelHeaders);
                db.ProdOrderCancelHeader.Remove(ProdOrderCancelHeaders);



                temp.ObjectState = Model.ObjectState.Deleted;
                // _MaterialPlanCancelHeaderService.Delete(temp);
                db.MaterialPlanCancelHeader.Attach(temp);
                db.MaterialPlanCancelHeader.Remove(temp);

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

                try
                {
                    // _unitOfWork.Save();
                    db.SaveChanges();
                    db.Configuration.AutoDetectChangesEnabled = true;
                }

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

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

                return(Json(new { success = true }));
            }
            return(PartialView("_Reason", vm));
        }
Пример #9
0
        public ActionResult DeleteConfirmed(ReasonViewModel vm)
        {
            List <LogTypeViewModel> LogList = new List <LogTypeViewModel>();

            if (ModelState.IsValid)
            {
                Person         person         = new PersonService(_unitOfWork).Find(vm.id);
                BusinessEntity businessentiry = _BusinessEntityService.Find(vm.id);
                JobWorker      jobworker      = _JobWorkerService.Find(vm.id);

                LogList.Add(new LogTypeViewModel
                {
                    ExObj = person,
                });

                LogList.Add(new LogTypeViewModel
                {
                    ExObj = businessentiry,
                });

                LogList.Add(new LogTypeViewModel
                {
                    ExObj = jobworker,
                });

                //Then find Ledger Account associated with the above Person.
                LedgerAccount ledgeraccount = _AccountService.GetLedgerAccountFromPersonId(vm.id);
                _AccountService.Delete(ledgeraccount.LedgerAccountId);

                //Then find all the Person Address associated with the above Person.
                PersonAddress personaddress = _PersonAddressService.GetShipAddressByPersonId(vm.id);
                _PersonAddressService.Delete(personaddress.PersonAddressID);


                IEnumerable <PersonContact> personcontact = new PersonContactService(_unitOfWork).GetPersonContactIdListByPersonId(vm.id);
                //Mark ObjectState.Delete to all the Person Contact For Above Person.
                foreach (PersonContact item in personcontact)
                {
                    new PersonContactService(_unitOfWork).Delete(item.PersonContactID);
                }

                IEnumerable <PersonBankAccount> personbankaccount = new PersonBankAccountService(_unitOfWork).GetPersonBankAccountIdListByPersonId(vm.id);
                //Mark ObjectState.Delete to all the Person Contact For Above Person.
                foreach (PersonBankAccount item in personbankaccount)
                {
                    new PersonBankAccountService(_unitOfWork).Delete(item.PersonBankAccountID);
                }

                IEnumerable <PersonProcess> personProcess = new PersonProcessService(_unitOfWork).GetPersonProcessIdListByPersonId(vm.id);
                //Mark ObjectState.Delete to all the Person Process For Above Person.
                foreach (PersonProcess item in personProcess)
                {
                    new PersonProcessService(_unitOfWork).Delete(item.PersonProcessId);
                }

                IEnumerable <PersonRegistration> personregistration = new PersonRegistrationService(_unitOfWork).GetPersonRegistrationIdListByPersonId(vm.id);
                //Mark ObjectState.Delete to all the Person Registration For Above Person.
                foreach (PersonRegistration item in personregistration)
                {
                    new PersonRegistrationService(_unitOfWork).Delete(item.PersonRegistrationID);
                }


                // Now delete the Parent JobWorker
                _JobWorkerService.Delete(jobworker);
                _BusinessEntityService.Delete(businessentiry);
                new PersonService(_unitOfWork).Delete(person);



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

                try
                {
                    _unitOfWork.Save();
                }

                catch (Exception ex)
                {
                    string message = _exception.HandleException(ex);
                    ModelState.AddModelError("", message);
                    return(PartialView("_Reason", vm));
                }


                LogActivity.LogActivityDetail(new ActiivtyLogViewModel
                {
                    DocTypeId       = new DocumentTypeService(_unitOfWork).FindByName(MasterDocCategoryConstants.JobWorker).DocumentTypeId,
                    DocId           = vm.id,
                    ActivityType    = (int)ActivityTypeContants.Deleted,
                    UserRemark      = vm.Reason,
                    User            = User.Identity.Name,
                    DocNo           = person.Name,
                    xEModifications = Modifications
                });

                return(Json(new { success = true }));
            }
            return(PartialView("_Reason", vm));
        }
Пример #10
0
        public ActionResult DeleteMaterialConfirmed(ReasonViewModel vm)
        {
            List <LogTypeViewModel> LogList = new List <LogTypeViewModel>();

            if (ModelState.IsValid)
            {
                var temp = _ProductService.Find(vm.id);

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

                _ProductService.Delete(vm.id);

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

                try
                {
                    _unitOfWork.Save();
                }

                catch (Exception ex)
                {
                    string message = _exception.HandleException(ex);
                    ModelState.AddModelError("", message);
                    return(PartialView("_Reason", vm));
                }

                LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                {
                    DocTypeId       = new DocumentTypeService(_unitOfWork).FindByName(MasterDocTypeConstants.Product).DocumentTypeId,
                    DocId           = vm.id,
                    ActivityType    = (int)ActivityTypeContants.Deleted,
                    UserRemark      = vm.Reason,
                    xEModifications = Modifications,
                }));

                //Deleting Existing Images

                var xtemp = System.Web.HttpContext.Current.Server.MapPath("~/Uploads/" + temp.ImageFolderName + "/" + temp.ImageFileName);
                if (System.IO.File.Exists(System.Web.HttpContext.Current.Server.MapPath("~/Uploads/" + temp.ImageFolderName + "/" + temp.ImageFileName)))
                {
                    System.IO.File.Delete(System.Web.HttpContext.Current.Server.MapPath("~/Uploads/" + temp.ImageFolderName + "/" + temp.ImageFileName));
                }

                //Deleting Thumbnail Image:

                if (System.IO.File.Exists(System.Web.HttpContext.Current.Server.MapPath("~/Uploads/" + temp.ImageFolderName + "/Thumbs/" + temp.ImageFileName)))
                {
                    System.IO.File.Delete(System.Web.HttpContext.Current.Server.MapPath("~/Uploads/" + temp.ImageFolderName + "/Thumbs/" + temp.ImageFileName));
                }

                //Deleting Medium Image:
                if (System.IO.File.Exists(System.Web.HttpContext.Current.Server.MapPath("~/Uploads/" + temp.ImageFolderName + "/Medium/" + temp.ImageFileName)))
                {
                    System.IO.File.Delete(System.Web.HttpContext.Current.Server.MapPath("~/Uploads/" + temp.ImageFolderName + "/Medium/" + temp.ImageFileName));
                }

                return(Json(new { success = true }));
            }
            return(PartialView("_Reason", vm));
        }
        public ActionResult Delete(ReasonViewModel vm)
        {
            if (ModelState.IsValid)
            {
                List <LogTypeViewModel> LogList = new List <LogTypeViewModel>();

                int?StockHeaderId = 0;
                var PackingHeader = _PackingHeaderService.GetPackingHeader(vm.id);
                int status        = PackingHeader.Status;

                LogList.Add(new LogTypeViewModel
                {
                    ExObj = PackingHeader,
                });

                StockHeaderId = PackingHeader.StockHeaderId;

                new StockUidService(_unitOfWork).DeleteStockUidForDocHeader(PackingHeader.PackingHeaderId, PackingHeader.DocTypeId, PackingHeader.SiteId, PackingHeader.DivisionId);

                List <int> StockIssueIdList   = new List <int>();
                List <int> StockReceiveIdList = new List <int>();


                var PackingLine = new PackingLineService(_unitOfWork).GetPackingLineForHeaderId(vm.id).ToList();

                foreach (var item in PackingLine)
                {
                    LogList.Add(new LogTypeViewModel
                    {
                        ExObj = item,
                    });

                    if (item.StockIssueId != null)
                    {
                        StockIssueIdList.Add((int)item.StockIssueId);
                    }

                    if (item.StockReceiveId != null)
                    {
                        StockReceiveIdList.Add((int)item.StockReceiveId);
                    }


                    if (item.ProductUidId != null && item.ProductUidId != 0)
                    {
                        ProductUidDetail ProductUidDetail = new ProductUidService(_unitOfWork).FGetProductUidLastValues((int)item.ProductUidId, "Packing-" + vm.id.ToString());

                        ProductUid ProductUid = new ProductUidService(_unitOfWork).Find((int)item.ProductUidId);


                        ProductUid.LastTransactionDocDate   = item.ProductUidLastTransactionDocDate;
                        ProductUid.LastTransactionDocId     = item.ProductUidLastTransactionDocId;
                        ProductUid.LastTransactionDocNo     = item.ProductUidLastTransactionDocNo;
                        ProductUid.LastTransactionDocTypeId = item.ProductUidLastTransactionDocTypeId;
                        ProductUid.LastTransactionPersonId  = item.ProductUidLastTransactionPersonId;
                        ProductUid.CurrenctGodownId         = item.ProductUidCurrentGodownId;
                        ProductUid.CurrenctProcessId        = item.ProductUidCurrentProcessId;
                        ProductUid.Status = item.ProductUidStatus;

                        //ProductUid.LastTransactionDocDate = ProductUidDetail.LastTransactionDocDate;
                        //ProductUid.LastTransactionDocId = ProductUidDetail.LastTransactionDocId;
                        //ProductUid.LastTransactionDocNo = ProductUidDetail.LastTransactionDocNo;
                        //ProductUid.LastTransactionDocTypeId = ProductUidDetail.LastTransactionDocTypeId;
                        //ProductUid.LastTransactionPersonId = ProductUidDetail.LastTransactionPersonId;
                        //ProductUid.CurrenctGodownId = ProductUidDetail.CurrenctGodownId;
                        //ProductUid.CurrenctProcessId = ProductUidDetail.CurrenctProcessId;

                        new ProductUidService(_unitOfWork).Update(ProductUid);
                    }


                    new PackingLineService(_unitOfWork).Delete(item.PackingLineId);
                }


                foreach (var item in StockIssueIdList)
                {
                    new StockService(_unitOfWork).DeleteStock(item);
                }

                foreach (var item in StockReceiveIdList)
                {
                    new StockService(_unitOfWork).DeleteStock(item);
                }

                new PackingHeaderService(_unitOfWork).Delete(vm.id);


                if (StockHeaderId != null)
                {
                    new StockHeaderService(_unitOfWork).Delete((int)StockHeaderId);
                }

                XElement Modifications = new ModificationsCheckService().CheckChanges(LogList);
                //Commit the DB
                try
                {
                    _unitOfWork.Save();
                }

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

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

                return(Json(new { success = true }));
            }
            return(PartialView("_Reason", vm));
        }
        public ActionResult DeleteConfirmed(ReasonViewModel vm)
        {
            List <LogTypeViewModel> LogList = new List <LogTypeViewModel>();

            if (ModelState.IsValid)
            {
                var CalculationHeaderLedger = _CalculationHeaderLedgerAccountService.Find(vm.id);
                var LineRecords             = new CalculationLineLedgerAccountService(_unitOfWork).GetCalculationListForIndex(vm.id, vm.DocTypeId);
                var HeaderRecords           = _CalculationHeaderLedgerAccountService.GetCalculationListForIndex(vm.id, vm.DocTypeId);

                LogList.Add(new LogTypeViewModel
                {
                    ExObj = CalculationHeaderLedger,
                });

                foreach (var item in LineRecords)
                {
                    LogList.Add(new LogTypeViewModel
                    {
                        ExObj = item,
                    });

                    new CalculationLineLedgerAccountService(_unitOfWork).Delete(item.CalculationLineLedgerAccountId);
                }

                foreach (var item in HeaderRecords)
                {
                    LogList.Add(new LogTypeViewModel
                    {
                        ExObj = item,
                    });
                    new CalculationHeaderLedgerAccountService(_unitOfWork).Delete(item.CalculationHeaderLedgerAccountId);
                }
                XElement Modifications = new ModificationsCheckService().CheckChanges(LogList);
                try
                {
                    _unitOfWork.Save();
                }

                catch (Exception ex)
                {
                    string message = _exception.HandleException(ex);
                    ModelState.AddModelError("", message);
                    return(PartialView("_Reason", vm));
                }

                //LogActivity.LogActivityDetail(new DocumentTypeService(_unitOfWork).Find(MasterDocTypeConstants.CalculationLedgerAccount).DocumentTypeId,
                // CalculationHeaderLedger.CalculationHeaderLedgerAccountId,
                // null,
                // (int)ActivityTypeContants.Deleted,
                // vm.Reason,
                // User.Identity.Name,
                // "", Modifications);

                LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                {
                    DocTypeId       = new DocumentTypeService(_unitOfWork).FindByName(MasterDocTypeConstants.CalculationLedgerAccount).DocumentTypeId,
                    DocId           = CalculationHeaderLedger.CalculationHeaderLedgerAccountId,
                    ActivityType    = (int)ActivityTypeContants.Deleted,
                    UserRemark      = "",
                    xEModifications = Modifications,
                }));

                return(Json(new { success = true }));
            }
            return(PartialView("_Reason", vm));
        }
Пример #13
0
 public void Delete(ReasonViewModel vmReason, string UserName)
 {
     _MvcControllerRepository.Delete(vmReason.id);
 }
        public ActionResult DeleteConfirmed(ReasonViewModel vm)
        {
            List <LogTypeViewModel> LogList = new List <LogTypeViewModel>();

            if (ModelState.IsValid)
            {
                var temp = _ProductCollectionService.Find(vm.id);

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

                int RefDocTypeId = new DocumentTypeService(_unitOfWork).Find(MasterDocTypeConstants.ProductCollection).DocumentTypeId;

                var ProcSeqHeader = (from p in db.ProcessSequenceHeader
                                     where p.ReferenceDocId == temp.ProductCollectionId && p.ReferenceDocTypeId == RefDocTypeId
                                     select p).FirstOrDefault();

                if (ProcSeqHeader != null)
                {
                    var ProcSeqLines = (from p in db.ProcessSequenceLine
                                        where p.ProcessSequenceHeaderId == p.ProcessSequenceHeaderId
                                        select p).ToList();

                    foreach (var item in ProcSeqLines)
                    {
                        new ProcessSequenceLineService(_unitOfWork).Delete(item);
                    }

                    new ProcessSequenceHeaderService(_unitOfWork).Delete(ProcSeqHeader);
                }

                _ProductCollectionService.Delete(vm.id);

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

                try
                {
                    _unitOfWork.Save();
                }

                catch (Exception ex)
                {
                    string message = _exception.HandleException(ex);
                    ModelState.AddModelError("", message);
                    return(PartialView("_Reason", vm));
                }

                LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                {
                    DocTypeId       = new DocumentTypeService(_unitOfWork).FindByName(MasterDocTypeConstants.ProductCollection).DocumentTypeId,
                    DocId           = vm.id,
                    ActivityType    = (int)ActivityTypeContants.Deleted,
                    UserRemark      = vm.Reason,
                    xEModifications = Modifications,
                }));

                return(Json(new { success = true }));
            }
            return(PartialView("_Reason", vm));
        }
        public ActionResult Delete(ReasonViewModel vm)
        {
            if (ModelState.IsValid)
            {
                List <LogTypeViewModel> LogList = new List <LogTypeViewModel>();



                //string temp = (Request["Redirect"].ToString());
                //first find the Purchase Order Object based on the ID. (sience this object need to marked to be deleted IE. ObjectState.Deleted)
                var SaleOrderHeader = _SaleOrderHeaderService.GetSaleOrderHeader(vm.id);


                //For Updating Enquiry Header and Lines so that it can be edited and deleted as needed.
                if (SaleOrderHeader.ReferenceDocId != null && SaleOrderHeader.ReferenceDocId != 0)
                {
                    var SaleEnquiryHeader = (from H in context.SaleEnquiryHeader where H.SaleEnquiryHeaderId == SaleOrderHeader.ReferenceDocId && H.DocTypeId == SaleOrderHeader.ReferenceDocTypeId select H).FirstOrDefault();
                    if (SaleEnquiryHeader != null)
                    {
                        SaleEnquiryHeader Header = new SaleEnquiryHeaderService(_unitOfWork).Find(SaleEnquiryHeader.SaleEnquiryHeaderId);
                        Header.LockReason = null;
                        new SaleEnquiryHeaderService(_unitOfWork).Update(Header);

                        IEnumerable <SaleEnquiryLine> LineList = new SaleEnquiryLineService(_unitOfWork).GetSaleEnquiryLineListForHeader(SaleEnquiryHeader.SaleEnquiryHeaderId);
                        foreach (SaleEnquiryLine Line in LineList)
                        {
                            Line.LockReason = null;
                            new SaleEnquiryLineService(_unitOfWork).Update(Line);
                        }
                    }
                }



                LogList.Add(new LogTypeViewModel
                {
                    ExObj = SaleOrderHeader,
                });

                //Then find all the Purchase Order Header Line associated with the above ProductType.
                var SaleOrderLine = new SaleOrderLineService(_unitOfWork).GetSaleOrderLineList(vm.id);



                List <int> StockIdList = new List <int>();

                //Mark ObjectState.Delete to all the Purchase Order Lines.
                foreach (var item in SaleOrderLine)
                {
                    if (item.StockId != null)
                    {
                        StockIdList.Add((int)item.StockId);
                    }

                    LogList.Add(new LogTypeViewModel
                    {
                        ExObj = item,
                    });

                    new SaleOrderLineStatusService(_unitOfWork).Delete(item.SaleOrderLineId);

                    new SaleOrderLineService(_unitOfWork).Delete(item.SaleOrderLineId);
                }

                foreach (var item in StockIdList)
                {
                    if (item != null)
                    {
                        new StockService(_unitOfWork).DeleteStock((int)item);
                    }
                }

                int?StockHeaderId = null;
                StockHeaderId = SaleOrderHeader.StockHeaderId;

                int LedgerHeaderId = SaleOrderHeader.LedgerHeaderId ?? 0;


                // Now delete the Sale Order Header
                new SaleOrderHeaderService(_unitOfWork).Delete(vm.id);

                // Now delete the Ledger & Ledger Header
                if (LedgerHeaderId != 0)
                {
                    var LedgerList = new LedgerService(_unitOfWork).FindForLedgerHeader(LedgerHeaderId).ToList();
                    foreach (var item in LedgerList)
                    {
                        new LedgerService(_unitOfWork).Delete(item.LedgerId);
                    }
                    new LedgerHeaderService(_unitOfWork).Delete(LedgerHeaderId);
                }



                if (StockHeaderId != null)
                {
                    new StockHeaderService(_unitOfWork).Delete((int)StockHeaderId);
                }

                XElement Modifications = new ModificationsCheckService().CheckChanges(LogList);
                //Commit the DB
                try
                {
                    _unitOfWork.Save();
                }

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

                //Logging Activity

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

                return(Json(new { success = true }));
            }
            return(PartialView("_Reason", vm));
        }
Пример #16
0
        public ActionResult Delete(ReasonViewModel vm)
        {
            List <LogTypeViewModel> LogList = new List <LogTypeViewModel>();

            if (ModelState.IsValid)
            {
                //string temp = (Request["Redirect"].ToString());
                //first find the Purchase Order Object based on the ID. (sience this object need to marked to be deleted IE. ObjectState.Deleted)
                var ProductContentHeader = _ProductContentHeaderService.GetProductContentHeader(vm.id);

                LogList.Add(new LogTypeViewModel
                {
                    ExObj = ProductContentHeader,
                });


                //Then find all the Purchase Order Header Line associated with the above ProductType.
                var line = new ProductCustomGroupLineService(_unitOfWork).GetProductCustomGroupLineListForIndex(vm.id);

                //Mark ObjectState.Delete to all the Purchase Order Lines.
                foreach (var item in line)
                {
                    LogList.Add(new LogTypeViewModel
                    {
                        ExObj = item,
                    });

                    new ProductCustomGroupLineService(_unitOfWork).Delete(item.ProductCustomGroupLineId);
                }

                // Now delete the Purhcase Order Header
                _ProductContentHeaderService.Delete(vm.id);

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

                //Commit the DB
                try
                {
                    _unitOfWork.Save();
                }

                catch (Exception ex)
                {
                    string message = _exception.HandleException(ex);
                    ModelState.AddModelError("", message);
                    return(PartialView("_Reason", vm));
                }

                LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                {
                    DocTypeId       = new DocumentTypeService(_unitOfWork).FindByName(MasterDocTypeConstants.ProductContent).DocumentTypeId,
                    DocId           = vm.id,
                    ActivityType    = (int)ActivityTypeContants.Deleted,
                    UserRemark      = vm.Reason,
                    xEModifications = Modifications,
                }));

                return(Json(new { success = true }));
            }
            return(PartialView("_Reason", vm));
        }
        public ActionResult DeleteConfirmed(ReasonViewModel vm)
        {
            List <LogTypeViewModel> LogList = new List <LogTypeViewModel>();

            if (ModelState.IsValid)
            {
                Product product = _ProductService.Find(vm.id);

                LogList.Add(new LogTypeViewModel
                {
                    ExObj = product,
                });


                IEnumerable <BomDetail> bomdetail = _BomDetailService.GetBomDetailList(vm.id);
                //Mark ObjectState.Delete to all the Bom Detail For Above Bom.
                foreach (BomDetail item in bomdetail)
                {
                    LogList.Add(new LogTypeViewModel
                    {
                        ExObj = item,
                    });
                    _BomDetailService.Delete(item.BomDetailId);
                }


                var temp = (from L in db.BomDetail
                            where L.ProductId == vm.id
                            select new { BomDetailId = L.BomDetailId }).ToList();


                foreach (var item in temp)
                {
                    LogList.Add(new LogTypeViewModel
                    {
                        ExObj = item,
                    });

                    _BomDetailService.Delete(item.BomDetailId);
                }

                // Now delete the Parent Bom
                _ProductService.Delete(product);
                XElement Modifications = new ModificationsCheckService().CheckChanges(LogList);

                try
                {
                    _unitOfWork.Save();
                }

                catch (Exception ex)
                {
                    string message = _exception.HandleException(ex);
                    ModelState.AddModelError("", message);
                    return(PartialView("_Reason", vm));
                }

                LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                {
                    DocTypeId       = new DocumentTypeService(_unitOfWork).Find(MasterDocTypeConstants.DesignConsumption).DocumentTypeId,
                    DocId           = product.ProductId,
                    ActivityType    = (int)ActivityTypeContants.Deleted,
                    UserRemark      = vm.Reason,
                    xEModifications = Modifications,
                }));

                return(Json(new { success = true }));
            }
            return(PartialView("_Reason", vm));
        }
Пример #18
0
        public ActionResult DeleteConfirmed(ReasonViewModel vm)
        {
            #region BeforeSave
            bool BeforeSave = true;
            try
            {
                BeforeSave = PurchaseOrderAmendmentDocEvents.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";
            }
            #endregion

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

                var temp = db.PurchaseOrderAmendmentHeader.Find(vm.id);

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

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

                var lines = (from p in db.PurchaseOrderRateAmendmentLine
                             where p.PurchaseOrderAmendmentHeaderId == vm.id
                             select p).ToList();

                var LineIds = lines.Select(m => m.PurchaseOrderRateAmendmentLineId).ToArray();

                var PurchaseOrderRateAmendmentLineCharges = (from p in db.PurchaseOrderRateAmendmentLineCharge
                                                             where LineIds.Contains(p.LineTableId)
                                                             select p).ToList();

                foreach (var item in PurchaseOrderRateAmendmentLineCharges)
                {
                    item.ObjectState = Model.ObjectState.Deleted;
                    db.PurchaseOrderRateAmendmentLineCharge.Remove(item);
                }

                new PurchaseOrderLineStatusService(_unitOfWork).DeletePurchaseRateOnAmendmentMultiple(vm.id, ref db);

                foreach (var item in lines)
                {
                    LogList.Add(new LogTypeViewModel
                    {
                        ExObj = Mapper.Map <PurchaseOrderRateAmendmentLine>(item),
                    });

                    item.ObjectState = Model.ObjectState.Deleted;
                    db.PurchaseOrderRateAmendmentLine.Remove(item);
                }

                var headercharges = (from p in db.PurchaseOrderAmendmentHeaderCharges
                                     where p.HeaderTableId == vm.id
                                     select p).ToList();



                foreach (var item in headercharges)
                {
                    item.ObjectState = Model.ObjectState.Deleted;
                    db.PurchaseOrderAmendmentHeaderCharges.Remove(item);
                }


                temp.ObjectState = Model.ObjectState.Deleted;
                db.PurchaseOrderAmendmentHeader.Remove(temp);

                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["CSEXC"] += message;
                    return(PartialView("_Reason", vm));
                }

                try
                {
                    PurchaseOrderAmendmentDocEvents.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       = temp.DocTypeId,
                    DocId           = temp.PurchaseOrderAmendmentHeaderId,
                    ActivityType    = (int)ActivityTypeContants.Deleted,
                    UserRemark      = vm.Reason,
                    DocNo           = temp.DocNo,
                    xEModifications = Modifications,
                    DocDate         = temp.DocDate,
                    DocStatus       = temp.Status,
                }));

                return(Json(new { success = true }));
            }
            return(PartialView("_Reason", vm));
        }
        public ActionResult Delete(ReasonViewModel vm)
        {
            bool BeforeSave = true;

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

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

            ExcessMaterialHeader ExcessMaterialHeader = (from p in context.ExcessMaterialHeader
                                                         where p.ExcessMaterialHeaderId == vm.id
                                                         select p).FirstOrDefault();

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

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


                ExcessMaterialHeader ExRec = new ExcessMaterialHeader();
                ExRec = Mapper.Map <ExcessMaterialHeader>(ExcessMaterialHeader);
                ExcessMaterialHeader Rec = new ExcessMaterialHeader();

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

                //Then find all the Purchase Order Header Line associated with the above ProductType.
                //var ExcessMaterialLine = new ExcessMaterialLineService(_unitOfWork).GetExcessMaterialLineforDelete(vm.id);

                var ExcessMaterialLine = (from p in context.ExcessMaterialLine
                                          where p.ExcessMaterialHeaderId == vm.id
                                          select p).ToList();

                //var ProductUids = ExcessMaterialLine.Select(m => m.ProductUidId).ToArray();

                //var ProdUidRecords = (from p in context.ProductUid
                //                      where ProductUids.Contains(p.ProductUIDId)
                //                      select p).ToList();


                //new RequisitionLineStatusService(_unitOfWork).DeleteRequisitionQtyOnIssueMultiple(ExcessMaterialHeader.ExcessMaterialHeaderId, ref context);

                //Mark ObjectState.Delete to all the Purchase Order Lines.
                foreach (var item in ExcessMaterialLine)
                {
                    ExcessMaterialLine ExRecLine = new ExcessMaterialLine();
                    ExRecLine = Mapper.Map <ExcessMaterialLine>(item);
                    ExcessMaterialLine RecLine = new ExcessMaterialLine();

                    LogList.Add(new LogTypeViewModel
                    {
                        ExObj = ExRecLine,
                        Obj   = RecLine,
                    });

                    //if (item.ProductUidId != null && item.ProductUidId > 0)
                    //{
                    //    ProductUidDetail ProductUidDetail = new ProductUidService(_unitOfWork).FGetProductUidLastValues((int)item.ProductUidId, "ExcessMaterial Head-" + ExcessMaterialHeader.ExcessMaterialHeaderId.ToString());

                    //    ProductUid ProductUid = ProdUidRecords.Where(m => m.ProductUIDId == item.ProductUidId).FirstOrDefault();

                    //    ProductUid.LastTransactionDocDate = ProductUidDetail.LastTransactionDocDate;
                    //    ProductUid.LastTransactionDocId = ProductUidDetail.LastTransactionDocId;
                    //    ProductUid.LastTransactionDocNo = ProductUidDetail.LastTransactionDocNo;
                    //    ProductUid.LastTransactionDocTypeId = ProductUidDetail.LastTransactionDocTypeId;
                    //    ProductUid.LastTransactionPersonId = ProductUidDetail.LastTransactionPersonId;
                    //    ProductUid.CurrenctGodownId = ProductUidDetail.CurrenctGodownId;
                    //    ProductUid.CurrenctProcessId = ProductUidDetail.CurrenctProcessId;
                    //    ProductUid.ObjectState = Model.ObjectState.Modified;
                    //    context.ProductUid.Add(ProductUid);

                    //}

                    item.ObjectState = Model.ObjectState.Deleted;
                    context.ExcessMaterialLine.Remove(item);
                }

                ExcessMaterialHeader.ObjectState = Model.ObjectState.Deleted;
                context.ExcessMaterialHeader.Remove(ExcessMaterialHeader);

                //if (GatePassHeaderId.HasValue)
                //{

                //    var GatePassLines = (from p in context.GatePassLine
                //                         where p.GatePassHeaderId == GatePassHeaderId
                //                         select p).ToList();

                //    foreach (var item in GatePassLines)
                //    {
                //        item.ObjectState = Model.ObjectState.Deleted;
                //        context.GatePassLine.Remove(item);
                //    }

                //    GatePassHeader.ObjectState = Model.ObjectState.Deleted;

                //    context.GatePassHeader.Remove(GatePassHeader);

                //}

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

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

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

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

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

                return(Json(new { success = true }));
            }
            return(PartialView("_Reason", vm));
        }
        public void Delete(ReasonViewModel vm, string UserName)
        {
            List <LogTypeViewModel> LogList = new List <LogTypeViewModel>();

            var            JobReceiveHeader = Find(vm.id);
            GatePassHeader GatePassHEader   = new GatePassHeader();


            int?StockHeaderId = 0;

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

            StockHeaderId = JobReceiveHeader.StockHeaderId;

            //Then find all the Purchase Order Header Line associated with the above ProductType.
            //var JobReceiveLine = new JobReceiveLineService(_unitOfWork).GetJobReceiveLineforDelete(vm.id);
            var JobReceiveLine = (_unitOfWork.Repository <JobReceiveLine>().Query().Get().Where(m => m.JobReceiveHeaderId == vm.id)).ToList();

            var JOLineIds = JobReceiveLine.Select(m => m.JobReceiveLineId).ToArray();

            var JobReceiveLineStatusRecords = _unitOfWork.Repository <JobReceiveLineStatus>().Query().Get().Where(m => JOLineIds.Contains(m.JobReceiveLineId ?? 0)).ToList();

            var ProductUids = JobReceiveLine.Select(m => m.ProductUidId).ToArray();

            var BarCodeRecords = _unitOfWork.Repository <ProductUid>().Query().Get().Where(m => ProductUids.Contains(m.ProductUIDId)).ToList();


            List <int> StockIdList        = new List <int>();
            List <int> StockProcessIdList = new List <int>();

            foreach (var item in JobReceiveLineStatusRecords)
            {
                item.ObjectState = Model.ObjectState.Deleted;
                _unitOfWork.Repository <JobReceiveLineStatus>().Delete(item);
            }


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


                if (item.StockId != null)
                {
                    StockIdList.Add((int)item.StockId);
                }

                if (item.StockProcessId != null)
                {
                    StockProcessIdList.Add((int)item.StockProcessId);
                }

                item.ObjectState = Model.ObjectState.Deleted;
                _unitOfWork.Repository <JobReceiveLine>().Delete(item);
            }


            _stockService.DeleteStockMultiple(StockIdList);

            _stockProcessService.DeleteStockProcessDBMultiple(StockProcessIdList);


            // Now delete the Purhcase Order Header
            //_JobReceiveHeaderService.Delete(JobReceiveHeader);

            int ReferenceDocId     = JobReceiveHeader.JobReceiveHeaderId;
            int ReferenceDocTypeId = JobReceiveHeader.DocTypeId;


            JobReceiveHeader.ObjectState = Model.ObjectState.Deleted;
            Delete(JobReceiveHeader);


            if (StockHeaderId != null)
            {
                var StockHeader = _unitOfWork.Repository <StockHeader>().Find(StockHeaderId);

                StockHeader.ObjectState = Model.ObjectState.Deleted;
                _unitOfWork.Repository <StockHeader>().Delete(StockHeader);
            }

            XElement Modifications = _modificationCheck.CheckChanges(LogList);

            _unitOfWork.Save();


            _logger.LogActivityDetail(logVm.Map(new ActiivtyLogViewModel
            {
                DocTypeId       = JobReceiveHeader.DocTypeId,
                DocId           = JobReceiveHeader.JobReceiveHeaderId,
                ActivityType    = (int)ActivityTypeContants.Deleted,
                UserRemark      = vm.Reason,
                DocNo           = JobReceiveHeader.DocNo,
                xEModifications = Modifications,
                DocDate         = JobReceiveHeader.DocDate,
                DocStatus       = JobReceiveHeader.Status,
            }));
        }
Пример #21
0
        public ActionResult DeleteConfirmed(ReasonViewModel vm)
        {
            if (ModelState.IsValid)
            {
                List <LogTypeViewModel> LogList = new List <LogTypeViewModel>();

                db.Configuration.AutoDetectChangesEnabled = false;
                var temp = _MaterialPlanHeaderService.Find(vm.id);

                int status = temp.Status;

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


                List <ProdOrderLine> ProdOrderLines = new List <ProdOrderLine>();
                //List<ProdOrderLine> PurchaseIndentLines = new List<ProdOrderLine>();


                var materialplanline = new MaterialPlanLineService(_unitOfWork).GetMaterialPlanForDelete(vm.id).ToList();

                //var MAterialPlanForProdOrderLine = new MaterialPlanForProdOrderLineService(_unitOfWork).GetMAterialPlanForProdORderForMaterialPlan(item.MaterialPlanLineId).ToList();
                var MAterialPlanForProdOrderLine = (from L in db.MaterialPlanForProdOrderLine
                                                    join H in db.MaterialPlanForProdOrder on L.MaterialPlanForProdOrderId equals H.MaterialPlanForProdOrderId into MaterialPlanForProdOrderTable
                                                    from MaterialPlanForProdOrderTab in MaterialPlanForProdOrderTable.DefaultIfEmpty()
                                                    where MaterialPlanForProdOrderTab.MaterialPlanHeaderId == vm.id
                                                    select L).ToList();
                foreach (var item2 in MAterialPlanForProdOrderLine)
                {
                    LogList.Add(new LogTypeViewModel
                    {
                        ExObj = item2,
                    });

                    item2.ObjectState = Model.ObjectState.Deleted;
                    //new MaterialPlanForProdOrderLineService(_unitOfWork).Delete(item2.MaterialPlanForProdOrderLineId);
                    db.MaterialPlanForProdOrderLine.Attach(item2);
                    db.MaterialPlanForProdOrderLine.Remove(item2);
                }

                foreach (var item in materialplanline)
                {
                    //Deleting ProdOrderLines & HEaders
                    ProdOrderLines = new ProdOrderLineService(_unitOfWork).GetProdOrderLineForMaterialPlan(item.MaterialPlanLineId).ToList();

                    int[] LineIds = ProdOrderLines.Select(m => m.ProdOrderLineId).ToArray();

                    List <ProdOrderLineStatus> LineStatus = (from p in db.ProdOrderLineStatus
                                                             where LineIds.Contains(p.ProdOrderLineId.Value)
                                                             select p).ToList();

                    foreach (var LineStatitem in LineStatus)
                    {
                        LineStatitem.ObjectState = Model.ObjectState.Deleted;
                        db.ProdOrderLineStatus.Attach(LineStatitem);
                        db.ProdOrderLineStatus.Remove(LineStatitem);
                    }

                    foreach (var item2 in ProdOrderLines)
                    {
                        LogList.Add(new LogTypeViewModel
                        {
                            ExObj = item2,
                        });

                        item2.ObjectState = Model.ObjectState.Deleted;
                        db.ProdOrderLine.Attach(item2);
                        db.ProdOrderLine.Remove(item2);
                    }


                    //Deleting PurchaseIndentLines & Headers
                    //PurchaseIndentLines = new ProdOrderLineService(_unitOfWork).GetPurchOrProdLineForMaterialPlan(item.MaterialPlanLineId, ).ToList();
                    //foreach (var item2 in PurchaseIndentLines)
                    //{

                    //    LogList.Add(new LogTypeViewModel
                    //    {
                    //        ExObj = item2,
                    //    });

                    //    item2.ObjectState = Model.ObjectState.Deleted;
                    //    db.PurchaseIndentLine.Attach(item2);
                    //    db.PurchaseIndentLine.Remove(item2);
                    //}


                    //Deleting MaterialplanforSaleOrder
                    var MAterialPlanForSaleOrder = new MaterialPlanForSaleOrderService(_unitOfWork).GetMaterialPlanForSaleOrderForMaterialPlanline(item.MaterialPlanLineId).ToList();
                    foreach (var item2 in MAterialPlanForSaleOrder)
                    {
                        LogList.Add(new LogTypeViewModel
                        {
                            ExObj = item2,
                        });

                        item2.ObjectState = Model.ObjectState.Deleted;
                        //new MaterialPlanForSaleOrderService(_unitOfWork).Delete(item2);
                        db.MaterialPlanForSaleOrder.Attach(item2);
                        db.MaterialPlanForSaleOrder.Remove(item2);
                    }

                    //Deleting MaterialPlanForProdOrderLine
                    //var MAterialPlanForProdOrderLine = new MaterialPlanForProdOrderLineService(_unitOfWork).GetMAterialPlanForProdORderForMaterialPlan(item.MaterialPlanLineId).ToList();
                    //foreach (var item2 in MAterialPlanForProdOrderLine)
                    //{

                    //    LogList.Add(new LogTypeViewModel
                    //    {
                    //        ExObj = item2,
                    //    });

                    //    item2.ObjectState = Model.ObjectState.Deleted;
                    //    //new MaterialPlanForProdOrderLineService(_unitOfWork).Delete(item2.MaterialPlanForProdOrderLineId);
                    //    db.MaterialPlanForProdOrderLine.Attach(item2);
                    //    db.MaterialPlanForProdOrderLine.Remove(item2);
                    //}

                    //new MaterialPlanLineService(_unitOfWork).Delete(item.MaterialPlanLineId);

                    //MaterialPlanLine Si = (MaterialPlanLine) item;
                    MaterialPlanLine MPL = new MaterialPlanLineService(_unitOfWork).Find(item.MaterialPlanLineId);

                    LogList.Add(new LogTypeViewModel
                    {
                        ExObj = MPL,
                    });

                    MPL.ObjectState = Model.ObjectState.Deleted;

                    db.MaterialPlanLine.Attach(MPL);
                    db.MaterialPlanLine.Remove(MPL);
                }



                var ProdORderHeaders = new ProdOrderHeaderService(_unitOfWork).GetProdOrderListForMaterialPlan(vm.id).ToList();

                int[] ProdOrderIds = ProdORderHeaders.Select(m => m.ProdOrderHeaderId).ToArray();

                List <ProdOrderHeaderStatus> ProdOrderHeaderStatus = (from p in db.ProdOrderHeaderStatus
                                                                      where ProdOrderIds.Contains(p.ProdOrderHeaderId.Value)
                                                                      select p).ToList();

                foreach (var StatItem in ProdOrderHeaderStatus)
                {
                    StatItem.ObjectState = Model.ObjectState.Deleted;
                    db.ProdOrderHeaderStatus.Attach(StatItem);
                    db.ProdOrderHeaderStatus.Remove(StatItem);
                }
                foreach (var item2 in ProdORderHeaders)
                {
                    LogList.Add(new LogTypeViewModel
                    {
                        ExObj = item2,
                    });

                    item2.ObjectState = Model.ObjectState.Deleted;
                    // new ProdOrderHeaderService(_unitOfWork).Delete(item2.ProdOrderHeaderId);
                    db.ProdOrderHeader.Attach(item2);
                    db.ProdOrderHeader.Remove(item2);
                }
                //var PurchaseIndentHeaders = new PurchaseIndentHeaderService(_unitOfWork).GetPurchaseIndentListForMAterialPlan(vm.id).ToList();
                //foreach (var item2 in PurchaseIndentHeaders)
                //{
                //    LogList.Add(new LogTypeViewModel
                //    {
                //        ExObj = item2,
                //    });

                //    item2.ObjectState = Model.ObjectState.Deleted;
                //    //new PurchaseIndentHeaderService(_unitOfWork).Delete(item2.PurchaseIndentHeaderId);
                //    db.PurchaseIndentHeader.Attach(item2);
                //    db.PurchaseIndentHeader.Remove(item2);
                //}

                //Deleting MaterialPlanForProdORder
                var MaterialPlanForProdOrder = new MaterialPlanForProdOrderService(_unitOfWork).GetMAterialPlanForProdORderForMaterialPlan(vm.id).ToList();
                foreach (var item2 in MaterialPlanForProdOrder)
                {
                    LogList.Add(new LogTypeViewModel
                    {
                        ExObj = item2,
                    });

                    item2.ObjectState = Model.ObjectState.Deleted;
                    //new MaterialPlanForProdOrderService(_unitOfWork).Delete(item2);
                    db.MaterialPlanForProdOrder.Attach(item2);
                    db.MaterialPlanForProdOrder.Remove(item2);
                }

                temp.ObjectState = Model.ObjectState.Deleted;
                // _MaterialPlanHeaderService.Delete(temp);
                db.MaterialPlanHeader.Attach(temp);
                db.MaterialPlanHeader.Remove(temp);

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

                try
                {
                    // _unitOfWork.Save();
                    db.SaveChanges();
                    db.Configuration.AutoDetectChangesEnabled = true;
                }

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

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

                return(Json(new { success = true }));
            }
            return(PartialView("_Reason", vm));
        }
Пример #22
0
        public ActionResult DeleteConfirmed(ReasonViewModel vm)
        {
            List <LogTypeViewModel> LogList = new List <LogTypeViewModel>();

            if (ModelState.IsValid)
            {
                var temp = _RateListHeaderService.Find(vm.id);

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

                var PersonRateGroupList = _RateListPersonRateGroupService.GetRateListPersonRateGroupList(vm.id);

                foreach (var item in PersonRateGroupList)
                {
                    LogList.Add(new LogTypeViewModel
                    {
                        ExObj = Mapper.Map <RateListPersonRateGroup>(item),
                    });
                    _RateListPersonRateGroupService.Delete(item.RateListPersonRateGroupId);
                }
                var ProductRateGroupList = _RateListProductRateGroupService.GetRateListProductRateGroupList(vm.id);
                foreach (var item in ProductRateGroupList)
                {
                    LogList.Add(new LogTypeViewModel
                    {
                        ExObj = Mapper.Map <RateListProductRateGroup>(item),
                    });
                    _RateListProductRateGroupService.Delete(item.RateListProductRateGroupId);
                }

                _RateListHeaderService.Delete(vm.id);
                XElement Modifications = new ModificationsCheckService().CheckChanges(LogList);
                try
                {
                    _unitOfWork.Save();
                }

                catch (Exception ex)
                {
                    string message = _exception.HandleException(ex);
                    ModelState.AddModelError("", message);
                    return(PartialView("_Reason", vm));
                }

                LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                {
                    DocTypeId       = new DocumentTypeService(_unitOfWork).FindByName(MasterDocTypeConstants.RateListHeader).DocumentTypeId,
                    DocId           = vm.id,
                    ActivityType    = (int)ActivityTypeContants.Deleted,
                    UserRemark      = vm.Reason,
                    xEModifications = Modifications,
                    DocNo           = temp.RateListName,
                }));

                return(Json(new { success = true }));
            }
            return(PartialView("_Reason", vm));
        }
Пример #23
0
        public ActionResult Delete(ReasonViewModel vm)
        {
            bool BeforeSave = true;

            try
            {
                BeforeSave = MaterialRequestDocEvents.beforeHeaderDeleteEvent(this, new StockEventArgs(vm.id), ref context);
            }
            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 RequisitionHeader = _RequisitionHeaderService.Find(vm.id);

                var RequisitionHeader = (from p in context.RequisitionHeader
                                         where p.RequisitionHeaderId == vm.id
                                         select p).FirstOrDefault();

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

                RequisitionHeader ExRec = new RequisitionHeader();
                ExRec = Mapper.Map <RequisitionHeader>(RequisitionHeader);

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

                //Then find all the Purchase Order Header Line associated with the above ProductType.
                //var RequisitionLine = new RequisitionLineService(_unitOfWork).GetRequisitionLineforDelete(vm.id);

                var RequisitionLine = (from p in context.RequisitionLine
                                       where p.RequisitionHeaderId == vm.id
                                       select p).ToList();
                var RequisitionIds = RequisitionLine.Select(m => m.RequisitionLineId).ToArray();

                var RequisitionLineStatusRecords = (from p in context.RequisitionLineStatus
                                                    where RequisitionIds.Contains(p.RequisitionLineId.Value)
                                                    select p).ToList();

                //Mark ObjectState.Delete to all the Purchase Order Lines.
                foreach (var item in RequisitionLine)
                {
                    RequisitionLine ExRecLine = new RequisitionLine();
                    ExRecLine = Mapper.Map <RequisitionLine>(item);

                    LogList.Add(new LogTypeViewModel
                    {
                        ExObj = ExRecLine,
                    });

                    //new RequisitionLineStatusService(_unitOfWork).Delete(item.RequisitionLineId);

                    var StatRecord = RequisitionLineStatusRecords.Where(m => m.RequisitionLineId == item.RequisitionLineId).FirstOrDefault();
                    StatRecord.ObjectState = Model.ObjectState.Deleted;

                    context.RequisitionLineStatus.Remove(StatRecord);

                    //new RequisitionLineService(_unitOfWork).Delete(item.RequisitionLineId);
                    item.ObjectState = Model.ObjectState.Deleted;
                    context.RequisitionLine.Remove(item);
                }

                // Now delete the Purhcase Order Header
                //new RequisitionHeaderService(_unitOfWork).Delete(RequisitionHeader);
                RequisitionHeader.ObjectState = Model.ObjectState.Deleted;
                context.RequisitionHeader.Remove(RequisitionHeader);

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

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

                    context.SaveChanges();
                }

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

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


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

                return(Json(new { success = true }));
            }
            return(PartialView("_Reason", vm));
        }
Пример #24
0
        public ActionResult Delete(ReasonViewModel vm)
        {
            bool BeforeSave = true;

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

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

            StockHeader StockHeader = (from p in context.StockHeader
                                       where p.StockHeaderId == vm.id
                                       select p).FirstOrDefault();

            var GatePassHeader = (from p in context.GatePassHeader
                                  where p.GatePassHeaderId == StockHeader.GatePassHeaderId
                                  select p).FirstOrDefault();

            if (GatePassHeader != null && GatePassHeader.Status == (int)StatusConstants.Submitted)
            {
                BeforeSave         = false;
                TempData["CSEXC"] += "Cannot delete record because gatepass is submitted.";
            }


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

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


                StockHeader ExRec = new StockHeader();
                ExRec = Mapper.Map <StockHeader>(StockHeader);
                StockHeader Rec = new StockHeader();

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

                var StockLine = (from p in context.StockLine
                                 where p.StockHeaderId == vm.id
                                 select p).ToList();

                //Mark ObjectState.Delete to all the Purchase Order Lines.
                foreach (var item in StockLine)
                {
                    StockLine ExRecLine = new StockLine();
                    ExRecLine = Mapper.Map <StockLine>(item);
                    StockLine RecLine = new StockLine();

                    LogList.Add(new LogTypeViewModel
                    {
                        ExObj = ExRecLine,
                        Obj   = RecLine,
                    });

                    item.ObjectState = Model.ObjectState.Deleted;
                    context.StockLine.Remove(item);
                }

                var GatePassHeaderId = StockHeader.GatePassHeaderId;

                StockHeader.ObjectState = Model.ObjectState.Deleted;
                context.StockHeader.Remove(StockHeader);

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


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

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

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

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


                return(Json(new { success = true }));
            }
            return(PartialView("_Reason", vm));
        }
Пример #25
0
        public ActionResult Delete(ReasonViewModel vm)
        {
            if (ModelState.IsValid)
            {
                db.Configuration.AutoDetectChangesEnabled = false;

                PackingHeader Sd = (from H in db.PackingHeader where H.PackingHeaderId == vm.id select H).FirstOrDefault();


                var PackingLine = (from L in db.PackingLine where L.PackingHeaderId == vm.id select L).ToList();


                List <int> StockIdList = new List <int>();
                int        cnt         = 0;
                foreach (var item in PackingLine)
                {
                    if (item.StockIssueId != null)
                    {
                        StockIdList.Add((int)item.StockIssueId);
                    }

                    cnt = cnt + 1;
                    try
                    {
                        item.ObjectState = Model.ObjectState.Deleted;
                        db.PackingLine.Attach(item);
                        db.PackingLine.Remove(item);
                    }
                    catch (Exception e)
                    {
                        string str = e.Message;
                    }
                }



                foreach (var item in StockIdList)
                {
                    if (item != null)
                    {
                        StockAdj Adj = (from L in db.StockAdj
                                        where L.StockOutId == item
                                        select L).FirstOrDefault();

                        if (Adj != null)
                        {
                            new StockAdjService(_unitOfWork).Delete(Adj);
                        }

                        new StockService(_unitOfWork).DeleteStockDB((int)item, ref db, true);
                    }
                }

                int?StockHeaderId = null;
                StockHeaderId = Sd.StockHeaderId;

                Sd.ObjectState = Model.ObjectState.Deleted;
                db.PackingHeader.Attach(Sd);
                db.PackingHeader.Remove(Sd);



                if (StockHeaderId != null)
                {
                    StockHeader StockHeader = (from H in db.StockHeader where H.StockHeaderId == StockHeaderId select H).FirstOrDefault();
                    StockHeader.ObjectState = Model.ObjectState.Deleted;
                    db.StockHeader.Attach(StockHeader);
                    db.StockHeader.Remove(StockHeader);
                }


                //Commit the DB
                try
                {
                    db.SaveChanges();
                    db.Configuration.AutoDetectChangesEnabled = true;
                }

                catch (Exception ex)
                {
                    string message = _exception.HandleException(ex);
                    db.Configuration.AutoDetectChangesEnabled = true;
                    TempData["CSEXC"] += message;
                    PrepareViewBag(Sd.DocTypeId);
                    return(PartialView("_Reason", vm));
                }

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

                return(Json(new { success = true }));
            }
            return(PartialView("_Reason", vm));
        }
Пример #26
0
        public ActionResult Delete(ReasonViewModel vm)
        {
            bool BeforeSave = true;

            try
            {
                BeforeSave = JobConsumptionDocEvents.beforeHeaderDeleteEvent(this, new StockEventArgs(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)
                StockHeader StockHeader = (from p in db.StockHeader
                                           where p.StockHeaderId == vm.id
                                           select p).FirstOrDefault();

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

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

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


                List <int> StockProcessIdList = new List <int>();

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


                    if (item.StockProcessId != null)
                    {
                        StockProcessIdList.Add((int)item.StockProcessId);
                    }

                    item.ObjectState = Model.ObjectState.Deleted;
                    db.StockLine.Remove(item);
                    //new StockLineService(_unitOfWork).Delete(item);
                }

                foreach (var item in StockProcessIdList)
                {
                    new StockProcessService(_unitOfWork).DeleteStockProcessDB(item, ref db, true);
                }

                //if (StockHeader != null)
                //{
                //    new StockHeaderService(_unitOfWork).Delete(StockHeader.StockHeaderId);
                //}


                // Now delete the Purhcase Order Header
                //new StockHeaderService(_unitOfWork).Delete(StockHeader);

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

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

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

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

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

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

                return(Json(new { success = true }));
            }
            return(PartialView("_Reason", vm));
        }
Пример #27
0
        public ActionResult DeleteConfirmed(ReasonViewModel vm)
        {
            if (ModelState.IsValid)
            {
                Person         person         = new PersonService(_unitOfWork).Find(vm.id);
                BusinessEntity businessentiry = _BusinessEntityService.Find(vm.id);
                Agent          Agent          = _AgentService.Find(vm.id);

                ActivityLog al = new ActivityLog()
                {
                    ActivityType = (int)ActivityTypeContants.Deleted,
                    CreatedBy    = User.Identity.Name,
                    CreatedDate  = DateTime.Now,
                    DocId        = vm.id,
                    UserRemark   = vm.Reason,
                    Narration    = "Agent is deleted with Name:" + person.Name,
                    DocTypeId    = new DocumentTypeService(_unitOfWork).FindByName(TransactionDocCategoryConstants.SaleOrder).DocumentTypeId,
                    UploadDate   = DateTime.Now,
                };
                new ActivityLogService(_unitOfWork).Create(al);

                //Then find all the Person Address associated with the above Person.
                PersonAddress personaddress = _PersonAddressService.GetShipAddressByPersonId(vm.id);
                _PersonAddressService.Delete(personaddress.PersonAddressID);


                IEnumerable <PersonContact> personcontact = new PersonContactService(_unitOfWork).GetPersonContactIdListByPersonId(vm.id);
                //Mark ObjectState.Delete to all the Person Contact For Above Person.
                foreach (PersonContact item in personcontact)
                {
                    new PersonContactService(_unitOfWork).Delete(item.PersonContactID);
                }

                IEnumerable <PersonBankAccount> personbankaccount = new PersonBankAccountService(_unitOfWork).GetPersonBankAccountIdListByPersonId(vm.id);
                //Mark ObjectState.Delete to all the Person Contact For Above Person.
                foreach (PersonBankAccount item in personbankaccount)
                {
                    new PersonBankAccountService(_unitOfWork).Delete(item.PersonBankAccountID);
                }

                // Now delete the Parent Agent
                _AgentService.Delete(Agent);
                _BusinessEntityService.Delete(businessentiry);
                new PersonService(_unitOfWork).Delete(person);


                try
                {
                    _unitOfWork.Save();
                }

                catch (Exception ex)
                {
                    string message = _exception.HandleException(ex);
                    ModelState.AddModelError("", message);
                    return(PartialView("_Reason", vm));
                }
                return(Json(new { success = true }));
            }
            return(PartialView("_Reason", vm));
        }
Пример #28
0
        public ActionResult DeleteConfirmed(ReasonViewModel vm)
        {
            bool BeforeSave = true;

            try
            {
                BeforeSave = MaterialRequestCancelDocEvents.beforeHeaderDeleteEvent(this, new StockEventArgs(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>();

                //var temp = _RequisitionCancelHeaderService.Find(vm.id);

                var temp = (from p in db.RequisitionCancelHeader
                            where p.RequisitionCancelHeaderId == vm.id
                            select p).FirstOrDefault();

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


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

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

                //var lines = new RequisitionCancelLineService(_unitOfWork).GetRequisitionCancelLineForHeader(vm.id);
                var lines = (from p in db.RequisitionCancelLine
                             where p.RequisitionCancelHeaderId == vm.id
                             select p).ToList();

                new RequisitionLineStatusService(_unitOfWork).DeleteRequisitionQtyOnCancelMultiple(vm.id, ref db);

                foreach (var item in lines)
                {
                    RequisitionCancelLine ExRecLine = new RequisitionCancelLine();
                    ExRecLine = Mapper.Map <RequisitionCancelLine>(item);

                    LogList.Add(new LogTypeViewModel
                    {
                        ExObj = ExRecLine,
                    });

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

                    //new RequisitionCancelLineService(_unitOfWork).Delete(item.RequisitionCancelLineId);
                }


                //_RequisitionCancelHeaderService.Delete(vm.id);

                temp.ObjectState = Model.ObjectState.Deleted;
                db.RequisitionCancelHeader.Remove(temp);

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

                try
                {
                    if (EventException)
                    {
                        throw new Exception();
                    }
                    db.SaveChanges();
                }

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

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

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

                return(Json(new { success = true }));
            }
            return(PartialView("_Reason", vm));
        }
Пример #29
0
        public async Task <IActionResult> Details(uint id)
        {
            ReasonViewModel reason = await _repoService.GetById(id);                                //get the requested reason & present

            return(View(reason));
        }
Пример #30
0
        public ActionResult DeleteConfirmed(ReasonViewModel vm)
        {
            List <LogTypeViewModel> LogList = new List <LogTypeViewModel>();

            if (ModelState.IsValid)
            {
                var temp = _CalculationService.Find(vm.id);

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

                var footer = new CalculationFooterService(_unitOfWork).GetCalculationListForIndex(vm.id);
                foreach (var item in footer)
                {
                    LogList.Add(new LogTypeViewModel
                    {
                        ExObj = item,
                    });
                    new CalculationFooterService(_unitOfWork).Delete(item.Id);
                }

                var product = new CalculationProductService(_unitOfWork).GetCalculationListForIndex(vm.id);
                foreach (var item in product)
                {
                    LogList.Add(new LogTypeViewModel
                    {
                        ExObj = item,
                    });
                    new CalculationProductService(_unitOfWork).Delete(item.Id);
                }


                _CalculationService.Delete(vm.id);
                XElement Modifications = new ModificationsCheckService().CheckChanges(LogList);
                try
                {
                    _unitOfWork.Save();
                }

                catch (Exception ex)
                {
                    string message = _exception.HandleException(ex);
                    ModelState.AddModelError("", message);
                    return(PartialView("_Reason", vm));
                }

                //LogActivity.LogActivityDetail(new DocumentTypeService(_unitOfWork).Find(MasterDocTypeConstants.Calculation).DocumentTypeId,
                // temp.CalculationId,
                // null,
                // (int)ActivityTypeContants.Deleted,
                // vm.Reason,
                // User.Identity.Name,
                // temp.CalculationName, Modifications);

                LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                {
                    DocTypeId       = new DocumentTypeService(_unitOfWork).FindByName(MasterDocTypeConstants.Calculation).DocumentTypeId,
                    DocId           = vm.id,
                    ActivityType    = (int)ActivityTypeContants.Deleted,
                    UserRemark      = vm.Reason,
                    xEModifications = Modifications,
                }));

                return(Json(new { success = true }));
            }
            return(PartialView("_Reason", vm));
        }