示例#1
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 ProductCustomGroupHeader = _ProductCustomGroupHeaderService.GetProductCustomGroupHeader(vm.id);

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

                //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
                _ProductCustomGroupHeaderService.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.ProductCustomGroup).DocumentTypeId,
                    DocId           = vm.id,
                    ActivityType    = (int)ActivityTypeContants.Deleted,
                    UserRemark      = vm.Reason,
                    xEModifications = Modifications,
                }));

                return(Json(new { success = true }));
            }
            return(PartialView("_Reason", vm));
        }
示例#2
0
        public ActionResult DeletePost(PersonDocument vm)
        {
            List <LogTypeViewModel> LogList = new List <LogTypeViewModel>();

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

            _PersonDocumentService.Delete(vm.PersonDocumentID);
            XElement Modifications = new ModificationsCheckService().CheckChanges(LogList);

            try
            {
                _unitOfWork.Save();
            }

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

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

            return(Json(new { success = true }));
        }
        public ActionResult DeletePost(ReportLine pt)
        {
            List <LogTypeViewModel> LogList = new List <LogTypeViewModel>();

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

            _ReportLineService.Delete(pt);
            XElement Modifications = new ModificationsCheckService().CheckChanges(LogList);

            try
            {
                _unitOfWork.Save();
            }

            catch (Exception ex)
            {
                string message = _exception.HandleException(ex);
                ModelState.AddModelError("", message);
                return(View("_Create", pt));
            }

            LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
            {
                DocTypeId       = new DocumentTypeService(_unitOfWork).Find(TransactionDoctypeConstants.Report).DocumentTypeId,
                DocId           = pt.ReportHeaderId,
                DocLineId       = pt.ReportLineId,
                ActivityType    = (int)ActivityTypeContants.Deleted,
                xEModifications = Modifications,
            }));

            return(Json(new { success = true }));
        }
示例#4
0
        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 SaleDeliveryOrderHeader = _SaleDeliveryOrderHeaderService.GetSaleDeliveryOrderHeader(vm.id);

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

                //Then find all the Purchase Order Header Line associated with the above ProductType.
                var SaleDeliveryOrderLine = new SaleDeliveryOrderLineService(_unitOfWork).GetSaleDeliveryOrderLineList(vm.id);

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

                // Now delete the Purhcase Order Header
                new SaleDeliveryOrderHeaderService(_unitOfWork).Delete(vm.id);
                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       = SaleDeliveryOrderHeader.DocTypeId,
                    DocId           = SaleDeliveryOrderHeader.SaleDeliveryOrderHeaderId,
                    ActivityType    = (int)ActivityTypeContants.Deleted,
                    UserRemark      = vm.Reason,
                    DocNo           = SaleDeliveryOrderHeader.DocNo,
                    xEModifications = Modifications,
                    DocDate         = SaleDeliveryOrderHeader.DocDate,
                    DocStatus       = SaleDeliveryOrderHeader.Status,
                }));

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

                var temp = _ReportHeaderService.Find(vm.id);

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

                var line = new ReportLineService(_unitOfWork).GetReportLineList(vm.id);


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


                    new ReportLineService(_unitOfWork).Delete(item.ReportLineId);
                }

                _ReportHeaderService.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));
                }

                //Logging Activity

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

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

                var temp = _SaleOrderAmendmentHeaderService.Find(vm.id);

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

                var lines = new SaleOrderQtyAmendmentLineService(_unitOfWork).GetSaleOrderQtyAmendmentLineForHeader(vm.id);

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

                    new SaleOrderQtyAmendmentLineService(_unitOfWork).Delete(item.SaleOrderQtyAmendmentLineId);
                }

                _SaleOrderAmendmentHeaderService.Delete(vm.id);
                XElement Modifications = new ModificationsCheckService().CheckChanges(LogList);
                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       = temp.DocTypeId,
                    DocId           = temp.SaleOrderAmendmentHeaderId,
                    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));
        }
示例#7
0
        //[ValidateAntiForgeryToken]
        public ActionResult PriorityUpdate(int Id, string Priority)
        {

            if (ModelState.IsValid)
            {
                List<LogTypeViewModel> LogList = new List<LogTypeViewModel>();

                PurchaseOrderHeader Head = db.PurchaseOrderHeader.Find(Id);

                PurchaseOrderHeader ExRec = Mapper.Map<PurchaseOrderHeader>(Head);

                int t = (int)Enum.Parse(typeof(SaleOrderPriority), Priority);
                Head.Priority = t;
                Head.ModifiedBy = User.Identity.Name;
                Head.ModifiedDate = DateTime.Now;

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

                Head.ObjectState = Model.ObjectState.Modified;
                db.PurchaseOrderHeader.Add(Head);

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

                try
                {
                    db.SaveChanges();
                }
                catch (Exception ex)
                {
                    return Json(new { Success = false });
                }

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

                return Json(new { Success = true });
            }

            return Json(new { Success = false });

        }
示例#8
0
        public ActionResult Edit(Unit pt)
        {
            List <LogTypeViewModel> LogList = new List <LogTypeViewModel>();

            if (ModelState.IsValid)
            {
                Unit temp = _UnitService.Find(pt.UnitId);

                Unit ExRec = Mapper.Map <Unit>(temp);

                temp.UnitName       = pt.UnitName;
                temp.Symbol         = pt.Symbol;
                temp.FractionName   = pt.FractionName;
                temp.FractionUnits  = pt.FractionUnits;
                temp.FractionSymbol = pt.FractionSymbol;
                temp.DecimalPlaces  = pt.DecimalPlaces;
                temp.IsActive       = pt.IsActive;
                temp.ModifiedDate   = DateTime.Now;
                temp.ModifiedBy     = User.Identity.Name;
                temp.ObjectState    = Model.ObjectState.Modified;
                _UnitService.Update(temp);

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

                try
                {
                    _unitOfWork.Save();
                }

                catch (Exception ex)
                {
                    string message = _exception.HandleException(ex);
                    ModelState.AddModelError("", message);
                    return(View(pt));
                }

                LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                {
                    DocTypeId       = new DocumentTypeService(_unitOfWork).FindByName(MasterDocTypeConstants.Unit).DocumentTypeId,
                    DocNo           = temp.UnitName,
                    ActivityType    = (int)ActivityTypeContants.Modified,
                    xEModifications = Modifications,
                }));

                return(RedirectToAction("Index").Success("Data saved successfully"));
            }
            return(View(pt));
        }
        public ActionResult DeletePost(SaleOrderCancelLineViewModel vm)
        {
            List <LogTypeViewModel> LogList = new List <LogTypeViewModel>();

            SaleOrderCancelLine SaleOrderLine = _SaleOrderCancelLineService.Find(vm.SaleOrderCancelLineId);

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

            SaleOrderCancelHeader header = new SaleOrderCancelHeaderService(_unitOfWork).Find(SaleOrderLine.SaleOrderCancelHeaderId);

            new SaleOrderLineStatusService(_unitOfWork).UpdateSaleQtyOnCancel(SaleOrderLine.SaleOrderLineId, SaleOrderLine.SaleOrderCancelLineId, header.DocDate, 0);

            _SaleOrderCancelLineService.Delete(vm.SaleOrderCancelLineId);

            if (header.Status != (int)StatusConstants.Drafted && header.Status != (int)StatusConstants.Import)
            {
                header.Status       = (int)StatusConstants.Modified;
                header.ModifiedDate = DateTime.Now;
                header.ModifiedBy   = User.Identity.Name;
                new SaleOrderCancelHeaderService(_unitOfWork).Update(header);
            }
            XElement Modifications = new ModificationsCheckService().CheckChanges(LogList);

            try
            {
                _unitOfWork.Save();
            }

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

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

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

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

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

                _ChargeGroupProductService.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.ChargeGroupProduct).DocumentTypeId,
                // temp.ChargeGroupProductId,
                // null,
                // (int)ActivityTypeContants.Deleted,
                // vm.Reason,
                // User.Identity.Name,
                // temp.ChargeGroupProductName, Modifications);

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

                return(Json(new { success = true }));
            }
            return(PartialView("_Reason", vm));
        }
示例#11
0
        public ActionResult DeletePost(DispatchWaybillLineViewModel vm)
        {
            List <LogTypeViewModel> LogList = new List <LogTypeViewModel>();

            DispatchWaybillLine DispatchWaybillLine = _DispatchWaybillLineService.GetDispatchWaybillLineForLineId(vm.DispatchWaybillLineId);

            LogList.Add(new LogTypeViewModel
            {
                Obj = Mapper.Map <JobOrderLine>(DispatchWaybillLine),
            });

            _DispatchWaybillLineService.Delete(vm.DispatchWaybillLineId);
            DispatchWaybillHeader DispatchWaybillheader = new DispatchWaybillHeaderService(_unitOfWork).Find(DispatchWaybillLine.DispatchWaybillHeaderId);

            if (DispatchWaybillheader.Status != (int)StatusConstants.Drafted)
            {
                DispatchWaybillheader.Status = (int)StatusConstants.Modified;
                new DispatchWaybillHeaderService(_unitOfWork).Update(DispatchWaybillheader);
            }

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

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

            LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
            {
                DocTypeId       = DispatchWaybillheader.DocTypeId,
                DocId           = DispatchWaybillheader.DispatchWaybillHeaderId,
                DocLineId       = DispatchWaybillLine.DispatchWaybillLineId,
                ActivityType    = (int)ActivityTypeContants.Deleted,
                DocNo           = DispatchWaybillheader.DocNo,
                xEModifications = Modifications,
                DocDate         = DispatchWaybillheader.DocDate,
                DocStatus       = DispatchWaybillheader.Status,
            }));

            return(Json(new { success = true }));
        }
示例#12
0
        public ActionResult Edit(TdsGroup pt)
        {
            List <LogTypeViewModel> LogList = new List <LogTypeViewModel>();

            if (ModelState.IsValid)
            {
                TdsGroup temp = _TdsGroupService.Find(pt.TdsGroupId);

                TdsGroup ExRec = Mapper.Map <TdsGroup>(temp);

                temp.TdsGroupName = pt.TdsGroupName;
                temp.ModifiedDate = DateTime.Now;
                temp.ModifiedBy   = User.Identity.Name;
                temp.ObjectState  = Model.ObjectState.Modified;
                _TdsGroupService.Update(temp);

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

                try
                {
                    _unitOfWork.Save();
                }

                catch (Exception ex)
                {
                    string message = _exception.HandleException(ex);
                    ModelState.AddModelError("", message);
                    return(View("Create", pt));
                }

                LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                {
                    DocTypeId       = new DocumentTypeService(_unitOfWork).FindByName(MasterDocTypeConstants.TdsGroup).DocumentTypeId,
                    DocId           = temp.TdsGroupId,
                    ActivityType    = (int)ActivityTypeContants.Modified,
                    xEModifications = Modifications,
                }));

                return(RedirectToAction("Index").Success("Data saved successfully"));
            }
            return(View("Create", pt));
        }
        public ActionResult DeletePost(CalculationLineLedgerAccountViewModel vm)
        {
            List <LogTypeViewModel> LogList = new List <LogTypeViewModel>();

            CalculationLineLedgerAccount CalculationLineLedgerAccount = _CalculationLineLedgerAccountService.Find(vm.CalculationLineLedgerAccountId);

            _CalculationLineLedgerAccountService.Delete(CalculationLineLedgerAccount);

            LogList.Add(new LogTypeViewModel
            {
                ExObj = CalculationLineLedgerAccount,
            });
            XElement Modifications = new ModificationsCheckService().CheckChanges(LogList);

            try
            {
                _unitOfWork.Save();
            }

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

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


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

            return(Json(new { success = true }));
        }
示例#14
0
        public ActionResult DeletePost(ProcessSequenceLineViewModel vm)
        {
            List <LogTypeViewModel> LogList = new List <LogTypeViewModel>();

            ProcessSequenceLine ProcessSequenceLine = _ProcessSequenceLineService.GetProcessSequenceLine(vm.ProcessSequenceLineId);

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


            _ProcessSequenceLineService.Delete(vm.ProcessSequenceLineId);
            ProcessSequenceHeader header = new ProcessSequenceHeaderService(_unitOfWork).Find(ProcessSequenceLine.ProcessSequenceHeaderId);

            if (header.Status != (int)StatusConstants.Drafted)
            {
                header.Status = (int)StatusConstants.Modified;
                new ProcessSequenceHeaderService(_unitOfWork).Update(header);
            }

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

            try
            {
                _unitOfWork.Save();
            }

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

            LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
            {
                DocTypeId       = new DocumentTypeService(_unitOfWork).FindByName(MasterDocTypeConstants.ProcessSequence).DocumentTypeId,
                DocId           = vm.ProcessSequenceHeaderId,
                DocLineId       = vm.ProcessSequenceLineId,
                ActivityType    = (int)ActivityTypeContants.Deleted,
                xEModifications = Modifications,
            }));

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

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

                var DocType = db.DocumentType.Where(m => m.DocumentTypeName == MasterDocTypeConstants.DocumentTypeTimeExtension).FirstOrDefault();

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

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

                _DocumentTypeTimeExtensionService.Delete(temp);


                try
                {
                    db.SaveChanges();
                }

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

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

                return(Json(new { success = true }));
            }
            return(PartialView("_Reason", vm));
        }
示例#16
0
        public ActionResult DeleteConfirmed(int id)
        {
            List <LogTypeViewModel> LogList = new List <LogTypeViewModel>();

            //first find the ProductType Object based on the ID. (sience this object need to marked to be deleted IE. ObjectState.Deleted)
            var productType = _ProductTypeService.Find(id);

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

            //Then find all the ProductGroups associated with the above ProductType.
            var productGroups = new ProductGroupService(_unitOfWork).GetProductGroupListForItemType(id);

            //Mark ObjectState.Delete to all the Product Groups . see ProductGroupService.Delete()
            foreach (var prodGroup in productGroups)
            {
                LogList.Add(new LogTypeViewModel
                {
                    ExObj = prodGroup,
                });
                new ProductGroupService(_unitOfWork).Delete(prodGroup);
            }
            // Now delete the Parent ProductType
            _ProductTypeService.Delete(productType);

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

            //Commit the DB
            _unitOfWork.Save();


            LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
            {
                DocTypeId       = new DocumentTypeService(_unitOfWork).FindByName(MasterDocTypeConstants.ProductType).DocumentTypeId,
                DocId           = productType.ProductTypeId,
                ActivityType    = (int)ActivityTypeContants.Deleted,
                xEModifications = Modifications,
            }));

            return(RedirectToAction("Index").Success("Data deleted successfully"));
        }
        public ActionResult Delete(ReasonViewModel vm)
        {
            List <LogTypeViewModel> LogList = new List <LogTypeViewModel>();

            if (ModelState.IsValid)
            {
                var CustomDetail = _CustomDetailService.GetCustomDetail(vm.id);

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

                new CustomDetailService(_unitOfWork).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.CustomDetail).DocumentTypeId,
                    DocId           = CustomDetail.CustomDetailId,
                    ActivityType    = (int)ActivityTypeContants.Deleted,
                    UserRemark      = vm.Reason,
                    xEModifications = Modifications,
                }));

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

                var temp = new ProductBuyerService(_unitOfWork).Find(vm.ProductBuyerId);

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

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

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

                //Logging Activity
                LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                {
                    DocTypeId       = new DocumentTypeService(_unitOfWork).FindByName(MasterDocTypeConstants.ProductBuyer).DocumentTypeId,
                    DocId           = vm.ProductBuyerId,
                    ActivityType    = (int)ActivityTypeContants.Deleted,
                    xEModifications = Modifications,
                }));

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

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

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

                _ProductGroupProcessSettingsService.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));
        }
        public ActionResult _CreatePost(StockLineViewModel svm)
        {
            StockHeader temp = new StockHeaderService(_unitOfWork).Find(svm.StockHeaderId);
            StockLine   s    = Mapper.Map <StockLineViewModel, StockLine>(svm);

            if (svm.StockHeaderSettings != null)
            {
                if (svm.StockHeaderSettings.isMandatoryProcessLine == true && (svm.FromProcessId <= 0 || svm.FromProcessId == null))
                {
                    ModelState.AddModelError("FromProcessId", "The Process field is required");
                }
                if (svm.StockHeaderSettings.isMandatoryRate == true && svm.Rate <= 0)
                {
                    ModelState.AddModelError("Rate", "The Rate field is required");
                }
                if (svm.StockHeaderSettings.isMandatoryLineCostCenter == true && !svm.CostCenterId.HasValue)
                {
                    ModelState.AddModelError("CostCenterId", "The Cost Center field is required");
                }
            }

            bool BeforeSave = true;

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

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

            if (svm.ProductId <= 0)
            {
                ModelState.AddModelError("ProductId", "The Product field is required");
            }

            if (svm.StockLineId <= 0)
            {
                ViewBag.LineMode = "Create";
            }
            else
            {
                ViewBag.LineMode = "Edit";
            }

            if (ModelState.IsValid && BeforeSave && !EventException)
            {
                if (svm.StockLineId <= 0)
                {
                    s.CreatedDate  = DateTime.Now;
                    s.ModifiedDate = DateTime.Now;
                    s.CreatedBy    = User.Identity.Name;
                    s.DocNature    = StockNatureConstants.Issue;
                    s.ModifiedBy   = User.Identity.Name;
                    s.ProductUidId = svm.ProductUidId;
                    s.Sr           = _StockLineService.GetMaxSr(s.StockHeaderId);
                    s.ObjectState  = Model.ObjectState.Added;
                    db.StockLine.Add(s);

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

                        db.StockHeader.Add(temp);
                    }

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

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

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

                    try
                    {
                        StockIssueDocEvents.afterLineSaveEvent(this, new StockEventArgs(s.StockHeaderId, s.StockLineId, EventModeConstants.Add), ref db);
                    }
                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        TempData["CSEXCL"] += message;
                    }

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

                    return(RedirectToAction("_Create", new { id = svm.StockHeaderId }));
                }


                else
                {
                    List <LogTypeViewModel> LogList = new List <LogTypeViewModel>();
                    int       status   = temp.Status;
                    StockLine templine = _StockLineService.Find(s.StockLineId);

                    StockLine ExRec = new StockLine();
                    ExRec = Mapper.Map <StockLine>(templine);

                    templine.ProductId         = s.ProductId;
                    templine.ProductUidId      = s.ProductUidId;
                    templine.RequisitionLineId = s.RequisitionLineId;
                    templine.Specification     = s.Specification;
                    templine.Dimension1Id      = s.Dimension1Id;
                    templine.Dimension2Id      = s.Dimension2Id;
                    templine.Dimension3Id      = s.Dimension3Id;
                    templine.Dimension4Id      = s.Dimension4Id;
                    templine.CostCenterId      = s.CostCenterId;
                    templine.DocNature         = StockNatureConstants.Issue;
                    templine.Rate               = s.Rate;
                    templine.Amount             = s.Amount;
                    templine.LotNo              = s.LotNo;
                    templine.FromProcessId      = s.FromProcessId;
                    templine.Remark             = s.Remark;
                    templine.Qty                = s.Qty;
                    templine.Remark             = s.Remark;
                    templine.ReferenceDocId     = s.ReferenceDocId;
                    templine.ReferenceDocTypeId = s.ReferenceDocTypeId;

                    templine.ModifiedDate = DateTime.Now;
                    templine.ModifiedBy   = User.Identity.Name;
                    templine.ObjectState  = Model.ObjectState.Modified;
                    db.StockLine.Add(templine);

                    //if (templine.RequisitionLineId.HasValue)
                    //    new RequisitionLineStatusService(_unitOfWork).UpdateRequisitionQtyOnIssue(templine.RequisitionLineId.Value, templine.StockLineId, temp.DocDate, templine.Qty, ref db, true);


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


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


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

                    try
                    {
                        StockIssueDocEvents.onLineSaveEvent(this, new StockEventArgs(s.StockHeaderId, templine.StockLineId, EventModeConstants.Edit), ref db);
                    }
                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        TempData["CSEXCL"] += message;
                        EventException      = true;
                    }

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

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

                    try
                    {
                        StockIssueDocEvents.afterLineSaveEvent(this, new StockEventArgs(s.StockHeaderId, templine.StockLineId, EventModeConstants.Edit), ref db);
                    }
                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        TempData["CSEXC"] += message;
                    }

                    //Saving the Activity Log

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

                    //End of Saving the Activity Log

                    return(Json(new { success = true }));
                }
            }
            PrepareViewBag(svm);
            return(PartialView("_Create", svm));
        }
        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));
        }
        public ActionResult HeaderPost(SaleOrderHeaderIndexViewModel svm)
        {
            if (svm.DocDate > svm.DueDate)
            {
                ModelState.AddModelError("DueDate", "DueDate cannot be greater than DocDate");
            }

            #region DocTypeTimeLineValidation

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

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

            #endregion

            if (ModelState.IsValid && (TimePlanValidation || Continue))
            {
                #region CreateRecord
                if (svm.SaleOrderHeaderId == 0)
                {
                    SaleOrderHeader s = Mapper.Map <SaleOrderHeaderIndexViewModel, SaleOrderHeader>(svm);

                    s.ActualDueDate = s.DueDate;
                    s.CreatedDate   = DateTime.Now;
                    s.ModifiedDate  = DateTime.Now;
                    s.CreatedBy     = User.Identity.Name;
                    s.ModifiedBy    = User.Identity.Name;
                    s.Status        = (int)StatusConstants.Drafted;
                    _SaleOrderHeaderService.Create(s);

                    try
                    {
                        _unitOfWork.Save();
                    }

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

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

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

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

                    //string tempredirect = (Request["Redirect"].ToString());
                    SaleOrderHeader s         = Mapper.Map <SaleOrderHeaderIndexViewModel, SaleOrderHeader>(svm);
                    StringBuilder   logstring = new StringBuilder();
                    SaleOrderHeader temp      = _SaleOrderHeaderService.Find(s.SaleOrderHeaderId);

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

                    int status = temp.Status;

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

                    temp.DocTypeId           = s.DocTypeId;
                    temp.DocDate             = s.DocDate;
                    temp.DocNo               = s.DocNo;
                    temp.BuyerOrderNo        = s.BuyerOrderNo;
                    temp.SaleToBuyerId       = s.SaleToBuyerId;
                    temp.BillToBuyerId       = s.BillToBuyerId;
                    temp.CurrencyId          = s.CurrencyId;
                    temp.Priority            = s.Priority;
                    temp.UnitConversionForId = s.UnitConversionForId;
                    temp.ShipMethodId        = s.ShipMethodId;
                    temp.ShipAddress         = s.ShipAddress;
                    temp.DeliveryTermsId     = s.DeliveryTermsId;
                    temp.Remark              = s.Remark;
                    temp.DueDate             = s.DueDate;
                    temp.Advance             = s.Advance;
                    temp.FinancierId         = s.FinancierId;
                    temp.SalesExecutiveId    = s.SalesExecutiveId;
                    temp.ModifiedDate        = DateTime.Now;
                    temp.ModifiedBy          = User.Identity.Name;
                    _SaleOrderHeaderService.Update(temp);

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

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

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

                    return(RedirectToAction("Index", new { id = svm.DocTypeId }).Success("Data saved successfully"));
                }
                #endregion
            }
            PrepareViewBag(svm);
            ViewBag.Mode = "Add";
            return(View("Create", svm));
        }
示例#23
0
        public ActionResult Post(ProductTypeAttribute pt)
        {
            if (ModelState.IsValid)
            {
                if (pt.ProductTypeAttributeId <= 0)
                {
                    pt.CreatedBy    = User.Identity.Name;
                    pt.CreatedDate  = System.DateTime.Now;
                    pt.ModifiedDate = System.DateTime.Now;
                    pt.ModifiedBy   = User.Identity.Name;
                    _ProductTypeAttributeService.Create(pt);

                    try
                    {
                        _unitOfWork.Save();
                    }

                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        ModelState.AddModelError("", message);
                        ViewBag.id   = pt.ProductType_ProductTypeId;
                        ViewBag.Name = new ProductTypeService(_unitOfWork).Find(pt.ProductType_ProductTypeId).ProductTypeName;
                        return(View("Create", pt));
                    }

                    LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                    {
                        DocTypeId    = new DocumentTypeService(_unitOfWork).FindByName(MasterDocTypeConstants.ProductTypeAttribute).DocumentTypeId,
                        DocId        = pt.ProductTypeAttributeId,
                        ActivityType = (int)ActivityTypeContants.Added,
                    }));

                    return(RedirectToAction("Create", new { id = pt.ProductType_ProductTypeId }).Success("Data saved successfully"));
                }
                else
                {
                    List <LogTypeViewModel> LogList = new List <LogTypeViewModel>();

                    ProductTypeAttribute TypeAttribute = _ProductTypeAttributeService.Find(pt.ProductTypeAttributeId);

                    ProductTypeAttribute ExRec = Mapper.Map <ProductTypeAttribute>(TypeAttribute);

                    TypeAttribute.IsActive     = pt.IsActive;
                    TypeAttribute.DefaultValue = pt.DefaultValue;
                    TypeAttribute.Name         = pt.Name;
                    TypeAttribute.IsMandatory  = pt.IsMandatory;
                    TypeAttribute.DataType     = pt.DataType;
                    TypeAttribute.ListItem     = pt.ListItem;
                    TypeAttribute.ModifiedDate = DateTime.Now;
                    TypeAttribute.ModifiedBy   = User.Identity.Name;
                    _ProductTypeAttributeService.Update(TypeAttribute);

                    LogList.Add(new LogTypeViewModel
                    {
                        ExObj = ExRec,
                        Obj   = TypeAttribute,
                    });
                    XElement Modifications = new ModificationsCheckService().CheckChanges(LogList);

                    try
                    {
                        _unitOfWork.Save();
                    }

                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        ModelState.AddModelError("", message);
                        ViewBag.id   = pt.ProductType_ProductTypeId;
                        ViewBag.Name = new ProductTypeService(_unitOfWork).Find(pt.ProductType_ProductTypeId).ProductTypeName;
                        return(View("Create", pt));
                    }

                    LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                    {
                        DocTypeId       = new DocumentTypeService(_unitOfWork).FindByName(MasterDocTypeConstants.ProductTypeAttribute).DocumentTypeId,
                        DocId           = TypeAttribute.ProductTypeAttributeId,
                        ActivityType    = (int)ActivityTypeContants.Modified,
                        xEModifications = Modifications,
                    }));

                    return(RedirectToAction("Index", new { id = TypeAttribute.ProductType_ProductTypeId }).Success("Data saved successfully"));
                }
            }
            PrepareViewBag(pt);
            return(View(pt));
        }
        public ActionResult DeletePost(RequisitionCancelLineViewModel vm)
        {
            bool BeforeSave = true;

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

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


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


                RequisitionCancelLine RequisitionLine = (from p in db.RequisitionCancelLine
                                                         where p.RequisitionCancelLineId == vm.RequisitionCancelLineId
                                                         select p).FirstOrDefault();

                //RequisitionCancelLine RequisitionLine = _RequisitionCancelLineService.Find(vm.RequisitionCancelLineId);
                RequisitionCancelHeader header = new RequisitionCancelHeaderService(_unitOfWork).Find(RequisitionLine.RequisitionCancelHeaderId);

                RequisitionCancelLine ExRec = new RequisitionCancelLine();
                ExRec = Mapper.Map <RequisitionCancelLine>(RequisitionLine);

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

                new RequisitionLineStatusService(_unitOfWork).UpdateRequisitionQtyOnCancel(RequisitionLine.RequisitionLineId, RequisitionLine.RequisitionCancelLineId, header.DocDate, 0, ref db, true);

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

                if (header.Status != (int)StatusConstants.Drafted && header.Status != (int)StatusConstants.Import)
                {
                    header.Status       = (int)StatusConstants.Modified;
                    header.ModifiedBy   = User.Identity.Name;
                    header.ModifiedDate = DateTime.Now;
                    header.ObjectState  = Model.ObjectState.Modified;
                    db.RequisitionCancelHeader.Add(header);
                }

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


                try
                {
                    MaterialRequestCancelDocEvents.onLineDeleteEvent(this, new StockEventArgs(RequisitionLine.RequisitionCancelHeaderId, RequisitionLine.RequisitionCancelLineId), ref db);
                }
                catch (Exception ex)
                {
                    string message = _exception.HandleException(ex);
                    TempData["CSEXCL"] += message;
                    EventException      = true;
                }


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

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

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


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

            return(Json(new { success = true }));
        }
        public ActionResult _CreatePost(RequisitionCancelLineViewModel svm)
        {
            bool BeforeSave = true;

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

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


            if (svm.RequisitionCancelLineId <= 0)
            {
                ViewBag.LineMode = "Create";
            }
            else
            {
                ViewBag.LineMode = "Edit";
            }

            if (svm.RequisitionCancelLineId <= 0)
            {
                RequisitionCancelHeader temp = new RequisitionCancelHeaderService(_unitOfWork).Find(svm.RequisitionCancelHeaderId);

                RequisitionCancelLine s = new RequisitionCancelLine();
                decimal balqty          = (from p in db.ViewRequisitionBalance
                                           where p.RequisitionLineId == svm.RequisitionLineId
                                           select p.BalanceQty).FirstOrDefault();
                if (balqty < svm.Qty)
                {
                    ModelState.AddModelError("Qty", "Qty Exceeding Balance Qty");
                }
                if (svm.Qty == 0)
                {
                    ModelState.AddModelError("Qty", "Please Check Qty");
                }
                if (ModelState.IsValid && BeforeSave && !EventException)
                {
                    s.Remark = svm.Remark;
                    s.RequisitionCancelHeaderId = svm.RequisitionCancelHeaderId;
                    s.RequisitionLineId         = svm.RequisitionLineId;
                    s.Qty          = svm.Qty;
                    s.CreatedDate  = DateTime.Now;
                    s.ModifiedDate = DateTime.Now;
                    s.CreatedBy    = User.Identity.Name;
                    s.ModifiedBy   = User.Identity.Name;
                    s.ObjectState  = Model.ObjectState.Added;

                    db.RequisitionCancelLine.Add(s);

                    //_RequisitionCancelLineService.Create(s);

                    new RequisitionLineStatusService(_unitOfWork).UpdateRequisitionQtyOnCancel(s.RequisitionLineId, s.RequisitionCancelLineId, temp.DocDate, s.Qty, ref db, true);

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

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

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

                        db.SaveChanges();
                    }

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

                    try
                    {
                        MaterialRequestCancelDocEvents.afterLineSaveEvent(this, new StockEventArgs(s.RequisitionCancelHeaderId, s.RequisitionLineId, EventModeConstants.Add), ref db);
                    }
                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        TempData["CSEXCL"] += message;
                    }

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

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

                RequisitionCancelHeader temp = new RequisitionCancelHeaderService(_unitOfWork).Find(svm.RequisitionCancelHeaderId);
                int           status         = temp.Status;
                StringBuilder logstring      = new StringBuilder();

                RequisitionCancelLine s = _RequisitionCancelLineService.Find(svm.RequisitionCancelLineId);

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


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


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

                        new RequisitionLineStatusService(_unitOfWork).UpdateRequisitionQtyOnCancel(s.RequisitionLineId, s.RequisitionCancelLineId, temp.DocDate, s.Qty, ref db, true);
                    }

                    //_RequisitionCancelLineService.Update(s);
                    s.ObjectState = Model.ObjectState.Modified;
                    db.RequisitionCancelLine.Add(s);

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


                    if (temp.Status != (int)StatusConstants.Drafted)
                    {
                        temp.Status      = (int)StatusConstants.Modified;
                        temp.ObjectState = Model.ObjectState.Modified;
                        db.RequisitionCancelHeader.Add(temp);
                        //new RequisitionCancelHeaderService(_unitOfWork).Update(temp);
                    }

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

                    try
                    {
                        MaterialRequestCancelDocEvents.onLineSaveEvent(this, new StockEventArgs(s.RequisitionCancelHeaderId, s.RequisitionCancelLineId, EventModeConstants.Edit), ref db);
                    }
                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        TempData["CSEXC"] += message;
                        EventException     = true;
                    }

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

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

                    try
                    {
                        MaterialRequestCancelDocEvents.afterLineSaveEvent(this, new StockEventArgs(s.RequisitionCancelHeaderId, s.RequisitionCancelLineId, EventModeConstants.Edit), ref db);
                    }
                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        TempData["CSEXC"] += message;
                    }

                    //SAving the Activity Log::

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

                    //End Of Saving Activity Log

                    return(Json(new { success = true }));
                }
                return(PartialView("_Create", svm));
            }
        }
        public ActionResult _CreatePost(SaleOrderQtyAmendmentLineViewModel svm)
        {
            if (svm.SaleOrderQtyAmendmentLineId <= 0)
            {
                SaleOrderQtyAmendmentLine s = new SaleOrderQtyAmendmentLine();

                if (svm.Qty == 0)
                {
                    ModelState.AddModelError("Qty", "Please Check Qty");
                }
                if (ModelState.IsValid)
                {
                    s.Remark = svm.Remark;
                    s.SaleOrderAmendmentHeaderId = svm.SaleOrderAmendmentHeaderId;
                    s.SaleOrderLineId            = svm.SaleOrderLineId;
                    s.Qty          = svm.Qty;
                    s.CreatedDate  = DateTime.Now;
                    s.ModifiedDate = DateTime.Now;
                    s.CreatedBy    = User.Identity.Name;
                    s.ModifiedBy   = User.Identity.Name;
                    _SaleOrderQtyAmendmentLineService.Create(s);

                    SaleOrderAmendmentHeader temp2 = new SaleOrderAmendmentHeaderService(_unitOfWork).Find(s.SaleOrderAmendmentHeaderId);
                    if (temp2.Status != (int)StatusConstants.Drafted && temp2.Status != (int)StatusConstants.Import)
                    {
                        temp2.Status       = (int)StatusConstants.Modified; temp2.ModifiedBy = User.Identity.Name;
                        temp2.ModifiedDate = DateTime.Now;
                        new SaleOrderAmendmentHeaderService(_unitOfWork).Update(temp2);
                    }

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

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

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

                SaleOrderAmendmentHeader temp = new SaleOrderAmendmentHeaderService(_unitOfWork).Find(svm.SaleOrderAmendmentHeaderId);
                int           status          = temp.Status;
                StringBuilder logstring       = new StringBuilder();

                SaleOrderQtyAmendmentLine s = _SaleOrderQtyAmendmentLineService.Find(svm.SaleOrderQtyAmendmentLineId);

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


                if (ModelState.IsValid)
                {
                    if (svm.Qty > 0)
                    {
                        //Tracking the Modification::

                        if (status == (int)StatusConstants.Approved)
                        {
                            logstring.Append("Editing SaleOrderQtyAmendmentLineId No:" + svm.SaleOrderQtyAmendmentLineId + "::\n");
                            if ((s.Remark != svm.Remark))
                            {
                                logstring.Append(s.Remark + " Remark Modified to " + svm.Remark + "::\n");
                            }
                            if ((s.Qty != svm.Qty))
                            {
                                logstring.Append(s.Qty + " Qty Modified to " + svm.Qty + "::\n");
                            }
                        }
                        //Ennd of Checking Modifications

                        s.Remark       = svm.Remark;
                        s.Qty          = svm.Qty;
                        s.ModifiedBy   = User.Identity.Name;
                        s.ModifiedDate = DateTime.Now;
                    }

                    _SaleOrderQtyAmendmentLineService.Update(s);

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

                    new SaleOrderAmendmentHeaderService(_unitOfWork).Update(temp);

                    LogList.Add(new LogTypeViewModel
                    {
                        ExObj = ExRec,
                        Obj   = s,
                    });
                    XElement Modifications = new ModificationsCheckService().CheckChanges(LogList);
                    try
                    {
                        _unitOfWork.Save();
                    }
                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        TempData["CSEXCL"] += message;
                        return(PartialView("_Create", svm));
                    }

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

                    return(Json(new { success = true }));
                }
                return(PartialView("_Create", svm));
            }
        }
        public ActionResult Post(SaleInvoiceSettingsViewModel vm)
        {
            SaleInvoiceSetting pt = AutoMapper.Mapper.Map <SaleInvoiceSettingsViewModel, SaleInvoiceSetting>(vm);

            if (pt.CalculationId <= 0)
            {
                ModelState.AddModelError("CalculationId", "The Calculation field is required");
            }

            if (ModelState.IsValid)
            {
                if (vm.SaleInvoiceSettingId <= 0)
                {
                    pt.CreatedDate  = DateTime.Now;
                    pt.ModifiedDate = DateTime.Now;
                    pt.CreatedBy    = User.Identity.Name;
                    pt.ModifiedBy   = User.Identity.Name;
                    pt.ObjectState  = Model.ObjectState.Added;
                    _SaleInvoiceSettingService.Create(pt);

                    try
                    {
                        _unitOfWork.Save();
                    }

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

                    LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                    {
                        DocTypeId    = pt.DocTypeId,
                        DocId        = pt.SaleInvoiceSettingId,
                        ActivityType = (int)ActivityTypeContants.SettingsAdded,
                    }));



                    return(RedirectToAction("Index", "DirectSaleInvoiceHeader", new { id = vm.DocTypeId }).Success("Data saved successfully"));
                }
                else
                {
                    List <LogTypeViewModel> LogList = new List <LogTypeViewModel>();

                    SaleInvoiceSetting temp = _SaleInvoiceSettingService.Find(pt.SaleInvoiceSettingId);

                    SaleInvoiceSetting ExRec = Mapper.Map <SaleInvoiceSetting>(temp);

                    temp.filterContraDocTypes              = pt.filterContraDocTypes;
                    temp.filterLedgerAccountGroups         = pt.filterLedgerAccountGroups;
                    temp.filterLedgerAccounts              = pt.filterLedgerAccounts;
                    temp.filterProductGroups               = pt.filterProductGroups;
                    temp.filterProducts                    = pt.filterProducts;
                    temp.filterProductTypes                = pt.filterProductTypes;
                    temp.filterContraDivisions             = pt.filterContraDivisions;
                    temp.filterContraSites                 = pt.filterContraSites;
                    temp.filterPersonRoles                 = pt.filterPersonRoles;
                    temp.CalculationId                     = pt.CalculationId;
                    temp.SqlProcDocumentPrint_AfterApprove = pt.SqlProcDocumentPrint_AfterApprove;
                    temp.SqlProcDocumentPrint_AfterSubmit  = pt.SqlProcDocumentPrint_AfterSubmit;
                    temp.isVisibleDimension1               = pt.isVisibleDimension1;
                    temp.isVisibleDimension2               = pt.isVisibleDimension2;
                    temp.isVisibleDimension3               = pt.isVisibleDimension3;
                    temp.isVisibleDimension4               = pt.isVisibleDimension4;
                    temp.DocTypeDispatchReturnId           = pt.DocTypeDispatchReturnId;
                    temp.isVisibleLotNo                    = pt.isVisibleLotNo;
                    temp.SqlProcDocumentPrint              = pt.SqlProcDocumentPrint;
                    temp.CalculateDiscountOnRate           = pt.CalculateDiscountOnRate;
                    temp.DocTypePackingHeaderId            = pt.DocTypePackingHeaderId;
                    temp.SaleDispatchDocTypeId             = pt.SaleDispatchDocTypeId;
                    temp.SaleInvoiceReturnDocTypeId        = pt.SaleInvoiceReturnDocTypeId;
                    temp.SqlProcGatePass                   = pt.SqlProcGatePass;
                    temp.UnitConversionForId               = pt.UnitConversionForId;
                    temp.ImportMenuId                  = pt.ImportMenuId;
                    temp.isVisibleAgent                = pt.isVisibleAgent;
                    temp.isVisibleCurrency             = pt.isVisibleCurrency;
                    temp.isVisibleDeliveryTerms        = pt.isVisibleDeliveryTerms;
                    temp.isVisibleDealUnit             = pt.isVisibleDealUnit;
                    temp.isVisibleShipMethod           = pt.isVisibleShipMethod;
                    temp.isVisibleSpecification        = pt.isVisibleSpecification;
                    temp.isVisibleSalesTaxGroupPerson  = pt.isVisibleSalesTaxGroupPerson;
                    temp.isVisibleSalesTaxGroupProduct = pt.isVisibleSalesTaxGroupProduct;
                    temp.isVisibleProductUid           = pt.isVisibleProductUid;
                    temp.isVisibleProductCode          = pt.isVisibleProductCode;
                    temp.isVisibleBaleNo               = pt.isVisibleBaleNo;
                    temp.isVisibleDiscountPer          = pt.isVisibleDiscountPer;
                    temp.isVisiblePromoCode            = pt.isVisiblePromoCode;
                    temp.isVisibleForSaleOrder         = pt.isVisibleForSaleOrder;
                    temp.isVisibleWeight               = pt.isVisibleWeight;
                    temp.isVisibleFinancier            = pt.isVisibleFinancier;
                    temp.isVisibleSalesExecutive       = pt.isVisibleSalesExecutive;
                    temp.isVisibleFreeQty              = pt.isVisibleFreeQty;
                    temp.isVisibleRewardPoints         = pt.isVisibleRewardPoints;
                    temp.isVisibleCreditDays           = pt.isVisibleCreditDays;
                    temp.isVisibleTermsAndConditions   = pt.isVisibleTermsAndConditions;
                    temp.isVisibleShipToPartyAddress   = pt.isVisibleShipToPartyAddress;
                    temp.DoNotUpdateProductUidStatus   = pt.DoNotUpdateProductUidStatus;
                    temp.CurrencyId            = pt.CurrencyId;
                    temp.DeliveryTermsId       = pt.DeliveryTermsId;
                    temp.ShipMethodId          = pt.ShipMethodId;
                    temp.ProcessId             = pt.ProcessId;
                    temp.SalesTaxGroupPersonId = pt.SalesTaxGroupPersonId;
                    temp.GodownId = pt.GodownId;
                    temp.DocumentPrintReportHeaderId = pt.DocumentPrintReportHeaderId;
                    temp.ModifiedDate = DateTime.Now;
                    temp.ModifiedBy   = User.Identity.Name;
                    temp.ObjectState  = Model.ObjectState.Modified;
                    _SaleInvoiceSettingService.Update(temp);

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

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

                    try
                    {
                        _unitOfWork.Save();
                    }

                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        ModelState.AddModelError("", message);
                        PrepareViewBag();
                        return(View("Create", pt));
                    }

                    LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                    {
                        DocTypeId       = temp.DocTypeId,
                        DocId           = temp.SaleInvoiceSettingId,
                        ActivityType    = (int)ActivityTypeContants.SettingsModified,
                        xEModifications = Modifications,
                    }));

                    return(RedirectToAction("Index", "DirectSaleInvoiceHeader", new { id = vm.DocTypeId }).Success("Data saved successfully"));
                }
            }
            PrepareViewBag();
            return(View("Create", vm));
        }
        public ActionResult DeletePost(StockLineViewModel vm)
        {
            bool BeforeSave = true;

            try
            {
                BeforeSave = StockIssueDocEvents.beforeLineDeleteEvent(this, new StockEventArgs(vm.StockHeaderId, vm.StockLineId), ref db);
            }
            catch (Exception ex)
            {
                string message = _exception.HandleException(ex);
                TempData["CSEXC"] += message;
                EventException     = true;
            }

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

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

                //StockLine StockLine = _StockLineService.Find(vm.StockLineId);
                StockLine StockLine = (from p in db.StockLine
                                       where p.StockLineId == vm.StockLineId
                                       select p).FirstOrDefault();
                StockHeader header = new StockHeaderService(_unitOfWork).Find(StockLine.StockHeaderId);

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

                ProdUid = StockLine.ProductUidId;

                if (StockLine.RequisitionLineId.HasValue)
                {
                    new RequisitionLineStatusService(_unitOfWork).UpdateRequisitionQtyOnIssue(StockLine.RequisitionLineId.Value, StockLine.StockLineId, header.DocDate, 0, ref db, true);
                }

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

                if (header.Status != (int)StatusConstants.Drafted && header.Status != (int)StatusConstants.Import)
                {
                    header.Status       = (int)StatusConstants.Modified;
                    header.ModifiedDate = DateTime.Now;
                    header.ModifiedBy   = User.Identity.Name;
                    header.ObjectState  = Model.ObjectState.Modified;
                    db.StockHeader.Add(header);
                }


                //if (ProdUid != null && ProdUid > 0)
                //{
                //    ProductUidDetail ProductUidDetail = new ProductUidService(_unitOfWork).FGetProductUidLastValues((int)ProdUid, "Stock Head-" + vm.StockHeaderId.ToString());

                //    ProductUid ProductUid = new ProductUidService(_unitOfWork).Find((int)ProdUid);

                //    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;
                //    db.ProductUid.Add(ProductUid);
                //}


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

                try
                {
                    StockIssueDocEvents.onLineDeleteEvent(this, new StockEventArgs(StockLine.StockHeaderId, StockLine.StockLineId), ref db);
                }
                catch (Exception ex)
                {
                    string message = _exception.HandleException(ex);
                    TempData["CSEXC"] += message;
                    EventException     = true;
                }

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

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

                try
                {
                    StockIssueDocEvents.afterLineDeleteEvent(this, new StockEventArgs(StockLine.StockHeaderId, StockLine.StockLineId), ref db);
                }
                catch (Exception ex)
                {
                    string message = _exception.HandleException(ex);
                    TempData["CSEXC"] += message;
                }

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

            return(Json(new { success = true }));
        }
        public ActionResult Post(ProductBuyerViewModel vm)
        {
            ProductBuyer pt = AutoMapper.Mapper.Map <ProductBuyerViewModel, ProductBuyer>(vm);

            if (ModelState.IsValid)
            {
                if (vm.ProductBuyerId <= 0)
                {
                    pt.CreatedDate  = DateTime.Now;
                    pt.ModifiedDate = DateTime.Now;
                    pt.CreatedBy    = User.Identity.Name;
                    pt.ModifiedBy   = User.Identity.Name;
                    pt.ObjectState  = Model.ObjectState.Added;
                    _ProductBuyerService.Create(pt);

                    try
                    {
                        _unitOfWork.Save();
                    }

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

                    LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                    {
                        DocTypeId    = new DocumentTypeService(_unitOfWork).FindByName(MasterDocTypeConstants.ProductBuyer).DocumentTypeId,
                        DocId        = pt.ProductBuyerId,
                        ActivityType = (int)ActivityTypeContants.Added,
                    }));

                    return(RedirectToAction("Create", new { ProductId = pt.ProductId }).Success("Data saved successfully"));
                }
                else
                {
                    List <LogTypeViewModel> LogList = new List <LogTypeViewModel>();

                    ProductBuyer temp = _ProductBuyerService.Find(pt.ProductBuyerId);

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

                    temp.BuyerId             = pt.BuyerId;
                    temp.BuyerSku            = pt.BuyerSku;
                    temp.BuyerProductCode    = pt.BuyerProductCode;
                    temp.BuyerSpecification  = pt.BuyerSpecification;
                    temp.BuyerSpecification1 = pt.BuyerSpecification1;
                    temp.BuyerSpecification2 = pt.BuyerSpecification2;
                    temp.BuyerSpecification3 = pt.BuyerSpecification3;
                    temp.BuyerSpecification4 = pt.BuyerSpecification4;
                    temp.BuyerSpecification5 = pt.BuyerSpecification5;
                    temp.BuyerSpecification6 = pt.BuyerSpecification6;
                    temp.BuyerUpcCode        = pt.BuyerUpcCode;
                    temp.ModifiedDate        = DateTime.Now;
                    temp.ModifiedBy          = User.Identity.Name;
                    temp.ObjectState         = Model.ObjectState.Modified;
                    _ProductBuyerService.Update(temp);

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

                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        ModelState.AddModelError("", message);
                        return(View("Create", pt));
                    }

                    LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                    {
                        DocTypeId       = new DocumentTypeService(_unitOfWork).FindByName(MasterDocTypeConstants.ProductBuyer).DocumentTypeId,
                        DocId           = temp.ProductBuyerId,
                        ActivityType    = (int)ActivityTypeContants.Modified,
                        xEModifications = Modifications,
                    }));

                    return(RedirectToAction("Index", new { id = vm.ProductId }).Success("Data saved successfully"));
                }
            }
            return(View("Create", vm));
        }
示例#30
0
        public ActionResult HeaderPost(ProductContentHeader svm)
        {
            if (ModelState.IsValid)
            {
                if (svm.ProductContentHeaderId == 0)
                {
                    svm.CreatedDate  = DateTime.Now;
                    svm.ModifiedDate = DateTime.Now;
                    svm.CreatedBy    = User.Identity.Name;
                    svm.ModifiedBy   = User.Identity.Name;
                    _ProductContentHeaderService.Create(svm);

                    try
                    {
                        _unitOfWork.Save();
                    }

                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        ModelState.AddModelError("", message);
                        return(View("Create", svm));
                    }

                    LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                    {
                        DocTypeId    = new DocumentTypeService(_unitOfWork).FindByName(MasterDocTypeConstants.ProductContent).DocumentTypeId,
                        DocId        = svm.ProductContentHeaderId,
                        ActivityType = (int)ActivityTypeContants.Added,
                    }));

                    return(RedirectToAction("Edit", new { id = svm.ProductContentHeaderId }).Success("Data saved Successfully"));
                }
                else
                {
                    List <LogTypeViewModel> LogList = new List <LogTypeViewModel>();

                    ProductContentHeader temp = _ProductContentHeaderService.Find(svm.ProductContentHeaderId);

                    Calculation ExRec = Mapper.Map <Calculation>(temp);

                    temp.ProductContentName = svm.ProductContentName;
                    temp.IsActive           = svm.IsActive;
                    temp.ModifiedDate       = DateTime.Now;
                    temp.ModifiedBy         = User.Identity.Name;
                    _ProductContentHeaderService.Update(temp);

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

                    try
                    {
                        _unitOfWork.Save();
                    }

                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        ModelState.AddModelError("", message);
                        return(View("Create", svm));
                    }


                    LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                    {
                        DocTypeId       = new DocumentTypeService(_unitOfWork).FindByName(MasterDocTypeConstants.ProductContent).DocumentTypeId,
                        DocId           = temp.ProductContentHeaderId,
                        ActivityType    = (int)ActivityTypeContants.Modified,
                        xEModifications = Modifications,
                    }));

                    return(RedirectToAction("Index").Success("Data saved successfully"));
                }
            }
            return(View("Create", svm));
        }