예제 #1
0
        public ActionResult HeaderPost(ProductCustomGroupHeader svm)
        {
            if (ModelState.IsValid)
            {
                if (svm.ProductCustomGroupId == 0)
                {
                    svm.CreatedDate  = DateTime.Now;
                    svm.ModifiedDate = DateTime.Now;
                    svm.CreatedBy    = User.Identity.Name;
                    svm.ModifiedBy   = User.Identity.Name;
                    _ProductCustomGroupHeaderService.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.ProductCustomGroup).DocumentTypeId,
                        DocId        = svm.ProductCustomGroupId,
                        ActivityType = (int)ActivityTypeContants.Added,
                    }));

                    //return RedirectToAction("Create", "SaleOrderLine", new { Id = s.ProductCustomGroupHeaderId }).Success("Data saved successfully");
                    return(RedirectToAction("Edit", new { id = svm.ProductCustomGroupId }).Success("Data saved Successfully"));
                }
                else
                {
                    List <LogTypeViewModel> LogList = new List <LogTypeViewModel>();

                    ProductCustomGroupHeader temp = _ProductCustomGroupHeaderService.Find(svm.ProductCustomGroupId);

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

                    temp.ProductCustomGroupName = svm.ProductCustomGroupName;
                    temp.IsActive     = svm.IsActive;
                    temp.ModifiedDate = DateTime.Now;
                    temp.ModifiedBy   = User.Identity.Name;
                    _ProductCustomGroupHeaderService.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.ProductCustomGroup).DocumentTypeId,
                        DocId           = temp.ProductCustomGroupId,
                        ActivityType    = (int)ActivityTypeContants.Modified,
                        xEModifications = Modifications,
                    }));

                    return(RedirectToAction("Index").Success("Data saved successfully"));
                }
            }
            return(View("Create", svm));
        }
        public ActionResult Post(LedgerAccountViewModel vm)
        {
            LedgerAccount pt = AutoMapper.Mapper.Map <LedgerAccountViewModel, LedgerAccount>(vm);

            if (ModelState.IsValid)
            {
                if (vm.LedgerAccountId <= 0)
                {
                    Product pt1 = new Product();
                    pt1.ProductName          = vm.LedgerAccountName;
                    pt1.ProductCode          = vm.LedgerAccountSuffix;
                    pt1.ProductDescription   = vm.LedgerAccountName;
                    pt1.ProductGroupId       = new ProductGroupService(_unitOfWork).Find(ProductGroupConstants.LedgerAccount).ProductGroupId;
                    pt1.ProductCategoryId    = null;
                    pt1.ProductSpecification = null;
                    pt1.StandardCost         = 0;
                    pt1.SaleRate             = 0;
                    pt1.Tags   = null;
                    pt1.UnitId = UnitConstants.Nos;
                    pt1.SalesTaxGroupProductId = vm.SalesTaxGroupProductId;
                    pt1.IsActive              = vm.IsActive;
                    pt1.DivisionId            = (int)System.Web.HttpContext.Current.Session["DivisionId"];
                    pt1.ProfitMargin          = 0;
                    pt1.CarryingCost          = 0;
                    pt1.DefaultDimension1Id   = null;
                    pt1.DefaultDimension2Id   = null;
                    pt1.DefaultDimension3Id   = null;
                    pt1.DefaultDimension4Id   = null;
                    pt1.DiscontinueDate       = null;
                    pt1.DiscontinueReason     = null;
                    pt1.SalesTaxProductCodeId = null;
                    pt1.CreatedDate           = DateTime.Now;
                    pt1.ModifiedDate          = DateTime.Now;
                    pt1.CreatedBy             = User.Identity.Name;
                    pt1.ModifiedBy            = User.Identity.Name;
                    pt1.ObjectState           = Model.ObjectState.Added;
                    new ProductService(_unitOfWork).Create(pt1);


                    pt.ProductId    = pt1.ProductId;
                    pt.CreatedDate  = DateTime.Now;
                    pt.ModifiedDate = DateTime.Now;
                    pt.CreatedBy    = User.Identity.Name;
                    pt.ModifiedBy   = User.Identity.Name;
                    pt.ObjectState  = Model.ObjectState.Added;
                    _LedgerAccountService.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.LedgerAccount).DocumentTypeId,
                        DocId        = pt.LedgerAccountId,
                        ActivityType = (int)ActivityTypeContants.Added,
                    }));


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

                    LedgerAccount temp = _LedgerAccountService.Find(pt.LedgerAccountId);

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

                    temp.LedgerAccountName    = pt.LedgerAccountName;
                    temp.LedgerAccountGroupId = pt.LedgerAccountGroupId;
                    temp.LedgerAccountSuffix  = pt.LedgerAccountSuffix;
                    temp.IsActive             = pt.IsActive;
                    temp.ModifiedDate         = DateTime.Now;
                    temp.ModifiedBy           = User.Identity.Name;
                    temp.ObjectState          = Model.ObjectState.Modified;
                    _LedgerAccountService.Update(temp);


                    if (temp.ProductId != null)
                    {
                        Product pt1 = new ProductService(_unitOfWork).Find((int)temp.ProductId);
                        pt1.ProductName            = vm.LedgerAccountName;
                        pt1.ProductCode            = vm.LedgerAccountSuffix;
                        pt1.ProductDescription     = vm.LedgerAccountName;
                        pt1.SalesTaxGroupProductId = vm.SalesTaxGroupProductId;
                        pt1.IsActive     = vm.IsActive;
                        pt1.ModifiedDate = DateTime.Now;
                        pt1.ModifiedBy   = User.Identity.Name;
                        pt1.ObjectState  = Model.ObjectState.Modified;
                        new ProductService(_unitOfWork).Update(pt1);
                    }


                    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", vm));
                    }

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

                    return(RedirectToAction("Index").Success("Data saved successfully"));
                }
            }

            PrepareViewBag();
            return(View("Create", vm));
        }
예제 #3
0
        public ActionResult Post(QAGroupViewModel svm)
        {
            bool BeforeSave          = true;
            bool CostCenterGenerated = false;

            QAGroup s = Mapper.Map <QAGroupViewModel, QAGroup>(svm);

            #region BeforeSaveEvents
            try
            {
                if (svm.QAGroupId <= 0)
                {
                    BeforeSave = JobOrderDocEvents.beforeHeaderSaveEvent(this, new JobEventArgs(svm.QAGroupId, EventModeConstants.Add), ref context);
                }
                else
                {
                    BeforeSave = JobOrderDocEvents.beforeHeaderSaveEvent(this, new JobEventArgs(svm.QAGroupId, EventModeConstants.Edit), ref context);
                }
            }
            catch (Exception ex)
            {
                string message = _exception.HandleException(ex);
                TempData["CSEXC"] += message;
                EventException     = true;
            }

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

            #region DocTypeTimeLineValidation

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

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

            #endregion

            if (ModelState.IsValid && BeforeSave && !EventException && (TimePlanValidation || Continue))
            {
                //CreateLogic
                #region CreateRecord
                if (svm.QAGroupId <= 0)
                {
                    // s.GodownId= (int)System.Web.HttpContext.Current.Session["DefaultGodownId"];
                    s.CreatedDate  = DateTime.Now;
                    s.ModifiedDate = DateTime.Now;
                    s.CreatedBy    = User.Identity.Name;
                    s.ModifiedBy   = User.Identity.Name;
                    s.Status       = (int)StatusConstants.Drafted;
                    s.ObjectState  = Model.ObjectState.Added;
                    context.QAGroup.Add(s);
                    try
                    {
                        JobOrderDocEvents.onHeaderSaveEvent(this, new JobEventArgs(s.QAGroupId, EventModeConstants.Add), ref context);
                    }
                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        TempData["CSEXC"] += message;
                        EventException     = true;
                    }


                    try
                    {
                        if (EventException)
                        {
                            throw new Exception();
                        }
                        //_unitOfWork.Save();
                        context.SaveChanges();
                    }

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



                    try
                    {
                        JobOrderDocEvents.afterHeaderSaveEvent(this, new JobEventArgs(s.QAGroupId, EventModeConstants.Add), ref context);
                    }
                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        TempData["CSEXC"] += message;
                    }

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

                    //Update DocId in COstCenter


                    return(RedirectToAction("Modify", "QAGroup", new { Id = s.QAGroupId }).Success("Data saved successfully"));
                }
                #endregion


                //EditLogic
                #region EditRecord

                else
                {
                    bool GodownChanged = false;
                    List <LogTypeViewModel> LogList = new List <LogTypeViewModel>();

                    QAGroup temp  = context.QAGroup.Find(s.QAGroupId);
                    QAGroup ExRec = Mapper.Map <QAGroup>(temp);

                    int status = temp.Status;

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

                    temp.QaGroupName  = s.QaGroupName;
                    temp.Description  = s.Description;
                    temp.ModifiedDate = DateTime.Now;
                    temp.ModifiedBy   = User.Identity.Name;
                    temp.ObjectState  = Model.ObjectState.Modified;
                    context.QAGroup.Add(temp);
                    LogList.Add(new LogTypeViewModel
                    {
                        ExObj = ExRec,
                        Obj   = temp,
                    });

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

                    try
                    {
                        JobOrderDocEvents.onHeaderSaveEvent(this, new JobEventArgs(s.QAGroupId, EventModeConstants.Edit), ref context);
                    }
                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        TempData["CSEXC"] += message;
                        EventException     = true;
                    }

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

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

                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);

                        PrepareViewBag(svm.DocTypeId);
                        TempData["CSEXC"] += message;
                        ViewBag.id         = svm.DocTypeId;
                        ViewBag.Mode       = "Edit";
                        return(View("Create", svm));
                    }

                    try
                    {
                        JobOrderDocEvents.afterHeaderSaveEvent(this, new JobEventArgs(s.QAGroupId, EventModeConstants.Edit), ref context);
                    }
                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        TempData["CSEXC"] += message;
                    }

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

                    return(RedirectToAction("Index", new { id = svm.DocTypeId }).Success("Data saved successfully"));
                }
                #endregion
            }
            PrepareViewBag(svm.DocTypeId);
            ViewBag.Mode = "Add";
            return(View("Create", svm));
        }
        public ActionResult Post(ProductBuyerSettingsViewModel vm)
        {
            ProductBuyerSettings pt = AutoMapper.Mapper.Map <ProductBuyerSettingsViewModel, ProductBuyerSettings>(vm);


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

                    try
                    {
                        _unitOfWork.Save();
                    }

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

                    int DocTypeId = new DocumentTypeService(_unitOfWork).Find(MasterDocTypeConstants.Carpet).DocumentTypeId;

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



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

                    ProductBuyerSettings temp = _ProductBuyerSettingsService.Find(pt.ProductBuyerSettingsId);

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

                    temp.BuyerSpecificationDisplayName  = vm.BuyerSpecificationDisplayName;
                    temp.BuyerSpecification1DisplayName = vm.BuyerSpecification1DisplayName;
                    temp.BuyerSpecification2DisplayName = vm.BuyerSpecification2DisplayName;
                    temp.BuyerSpecification3DisplayName = vm.BuyerSpecification3DisplayName;
                    temp.BuyerSpecification4DisplayName = vm.BuyerSpecification4DisplayName;
                    temp.BuyerSpecification5DisplayName = vm.BuyerSpecification5DisplayName;
                    temp.BuyerSpecification6DisplayName = vm.BuyerSpecification6DisplayName;
                    temp.ModifiedDate = DateTime.Now;
                    temp.ModifiedBy   = User.Identity.Name;
                    temp.ObjectState  = Model.ObjectState.Modified;
                    _ProductBuyerSettingsService.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(vm);
                        return(View("Create", pt));
                    }

                    int DocTypeId = new DocumentTypeService(_unitOfWork).Find(MasterDocTypeConstants.Carpet).DocumentTypeId;

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

                    return(RedirectToAction("Index", "ProductBuyer", new { id = vm.ProductId }).Success("Data saved successfully"));
                }
            }
            PrepareViewBag(vm);
            return(View("Create", vm));
        }
예제 #5
0
        public ActionResult Post(Godown vm)
        {
            Godown pt = vm;

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


                    try
                    {
                        _GodownService.Create(pt);
                    }



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


                    _logger.LogActivityDetail(logVm.Map(new ActiivtyLogViewModel
                    {
                        DocTypeId    = Constants.DocumentTypeIdConstants.Godown,
                        DocId        = pt.GodownId,
                        ActivityType = (int)ActivityTypeContants.Added,
                    }));


                    //return RedirectToAction("Create").Success("Data saved successfully");
                    return(RedirectToAction("Modify", "Godown", new { Id = vm.GodownId }).Success("Data saved successfully"));
                }

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

                    Godown temp = _GodownService.Find(pt.GodownId);

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

                    temp.GodownCode   = pt.GodownCode;
                    temp.GodownName   = pt.GodownName;
                    temp.GateId       = pt.GateId;
                    temp.PersonId     = pt.PersonId;
                    temp.IsActive     = pt.IsActive;
                    temp.ModifiedDate = DateTime.Now;
                    temp.ModifiedBy   = User.Identity.Name;
                    temp.ObjectState  = Model.ObjectState.Modified;


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

                    XElement Modifications = _modificationCheck.CheckChanges(LogList);

                    try
                    {
                        _GodownService.Update(temp);
                    }

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


                    _logger.LogActivityDetail(logVm.Map(new ActiivtyLogViewModel
                    {
                        DocTypeId       = Constants.DocumentTypeIdConstants.Godown,
                        DocId           = temp.GodownId,
                        ActivityType    = (int)ActivityTypeContants.Modified,
                        xEModifications = Modifications,
                    }));

                    return(RedirectToAction("Index").Success("Data saved successfully"));
                }
            }
            return(View("Create", vm));
        }
        public ActionResult _ResultsPost(StockMasterDetailModel vm)
        {
            int         Cnt    = 0;
            StockHeader Header = new StockHeaderService(_unitOfWork).Find(vm.StockLineViewModel.FirstOrDefault().StockHeaderId);

            StockHeaderSettings Settings = new StockHeaderSettingsService(_unitOfWork).GetStockHeaderSettingsForDocument(Header.DocTypeId, Header.DivisionId, Header.SiteId);

            bool BeforeSave = true;

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

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

            if (ModelState.IsValid && BeforeSave && !EventException)
            {
                var CostCenterRecords = (from p in vm.StockLineViewModel
                                         where p.CostCenterId != null
                                         group p by p.CostCenterId into g
                                         select g).ToList();

                var CostCenterIds = CostCenterRecords.Select(m => m.Key).ToArray();

                var DBCostCenterStatus = (from p in db.CostCenterStatus
                                          where CostCenterIds.Contains(p.CostCenterId)
                                          select p).ToArray();


                foreach (var item in vm.StockLineViewModel)
                {
                    if (item.Qty != 0 && item.Rate > 0 && (Settings.isMandatoryLineCostCenter == true ? item.CostCenterId.HasValue : 1 == 1))
                    {
                        StockLine line = new StockLine();

                        StockProcessViewModel StockProcessViewModel = new StockProcessViewModel();

                        if (Header.StockHeaderId != null && Header.StockHeaderId != 0)//If Transaction Header Table Has Stock Header Id Then It will Save Here.
                        {
                            StockProcessViewModel.StockHeaderId = (int)Header.StockHeaderId;
                        }
                        else if (Cnt > 0)//If function will only post in stock process then after first iteration of loop the stock header id will go -1
                        {
                            StockProcessViewModel.StockHeaderId = -1;
                        }
                        else//If function will only post in stock process then this statement will execute.For Example Job consumption.
                        {
                            StockProcessViewModel.StockHeaderId = 0;
                        }
                        StockProcessViewModel.StockProcessId      = -Cnt;
                        StockProcessViewModel.DocHeaderId         = Header.StockHeaderId;
                        StockProcessViewModel.DocLineId           = line.StockLineId;
                        StockProcessViewModel.DocTypeId           = Header.DocTypeId;
                        StockProcessViewModel.StockHeaderDocDate  = Header.DocDate;
                        StockProcessViewModel.StockProcessDocDate = Header.DocDate;
                        StockProcessViewModel.DocNo              = Header.DocNo;
                        StockProcessViewModel.DivisionId         = Header.DivisionId;
                        StockProcessViewModel.SiteId             = Header.SiteId;
                        StockProcessViewModel.CurrencyId         = null;
                        StockProcessViewModel.PersonId           = Header.PersonId;
                        StockProcessViewModel.ProductId          = item.ProductId;
                        StockProcessViewModel.HeaderFromGodownId = null;
                        StockProcessViewModel.HeaderGodownId     = Header.GodownId;
                        StockProcessViewModel.HeaderProcessId    = Header.ProcessId;
                        StockProcessViewModel.GodownId           = Header.GodownId;
                        StockProcessViewModel.Remark             = Header.Remark;
                        StockProcessViewModel.Status             = Header.Status;
                        StockProcessViewModel.ProcessId          = Header.ProcessId;
                        StockProcessViewModel.LotNo              = null;
                        StockProcessViewModel.CostCenterId       = (item.CostCenterId == null ? Header.CostCenterId : item.CostCenterId);


                        if (item.Qty < 0)
                        {
                            StockProcessViewModel.Qty_Rec = Math.Abs(item.Qty);
                            StockProcessViewModel.Qty_Iss = 0;
                        }
                        else if (item.Qty > 0)
                        {
                            StockProcessViewModel.Qty_Iss = Math.Abs(item.Qty);
                            StockProcessViewModel.Qty_Rec = 0;
                        }

                        StockProcessViewModel.Rate          = item.Rate;
                        StockProcessViewModel.ExpiryDate    = null;
                        StockProcessViewModel.Specification = item.Specification;
                        StockProcessViewModel.Dimension1Id  = item.Dimension1Id;
                        StockProcessViewModel.Dimension2Id  = item.Dimension2Id;
                        StockProcessViewModel.Dimension3Id  = item.Dimension3Id;
                        StockProcessViewModel.Dimension4Id  = item.Dimension4Id;
                        StockProcessViewModel.CreatedBy     = User.Identity.Name;
                        StockProcessViewModel.CreatedDate   = DateTime.Now;
                        StockProcessViewModel.ModifiedBy    = User.Identity.Name;
                        StockProcessViewModel.ModifiedDate  = DateTime.Now;

                        string StockProcessPostingError = "";
                        StockProcessPostingError = new StockProcessService(_unitOfWork).StockProcessPostDB(ref StockProcessViewModel, ref db);

                        if (StockProcessPostingError != "")
                        {
                            string message = StockProcessPostingError;
                            ModelState.AddModelError("", message);
                            return(PartialView("_Results", vm));
                        }

                        line.StockProcessId = StockProcessViewModel.StockProcessId;



                        line.StockHeaderId = item.StockHeaderId;
                        line.Qty           = item.Qty;
                        line.ProductId     = item.ProductId;
                        line.LotNo         = item.LotNo;
                        line.Rate          = (decimal)item.Rate;
                        line.Amount        = Math.Round((decimal)item.Rate * item.Qty, Settings.LineRoundOff ?? 0);
                        line.Dimension1Id  = item.Dimension1Id;
                        line.Dimension2Id  = item.Dimension2Id;
                        line.Dimension3Id  = item.Dimension3Id;
                        line.Dimension4Id  = item.Dimension4Id;
                        line.DocNature     = StockNatureConstants.Receive;
                        line.CostCenterId  = item.CostCenterId;
                        line.FromProcessId = item.FromProcessId;
                        line.Specification = item.Specification;
                        line.CreatedDate   = DateTime.Now;
                        line.ModifiedDate  = DateTime.Now;
                        line.CreatedBy     = User.Identity.Name;
                        line.ModifiedBy    = User.Identity.Name;

                        line.ObjectState = Model.ObjectState.Added;
                        //_StockLineService.Create(line);
                        db.StockLine.Add(line);

                        Cnt = Cnt + 1;
                    }
                }

                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.StockHeader.Add(Header);
                }

                //ForUpdating CostCenterStatus Values//

                foreach (var item in DBCostCenterStatus)
                {
                    var CostCenterAmounts = db.StockLine.Local.Where(m => m.CostCenterId == item.CostCenterId).ToList();



                    if (CostCenterAmounts != null)
                    {
                        if (CostCenterAmounts.Sum(m => m.Amount) > 0)
                        {
                            item.AmountDr = (item.AmountDr ?? 0) + CostCenterAmounts.Sum(m => m.Amount);
                        }
                        else if (CostCenterAmounts.Sum(m => m.Amount) < 0)
                        {
                            item.AmountDr = (item.AmountDr ?? 0) + CostCenterAmounts.Sum(m => m.Amount);
                        }

                        item.ObjectState = Model.ObjectState.Modified;
                        db.CostCenterStatus.Add(item);
                    }
                }


                try
                {
                    RateConversionDocEvents.onLineSaveBulkEvent(this, new StockEventArgs(vm.StockLineViewModel.FirstOrDefault().StockHeaderId), 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("_Results", vm));
                }

                try
                {
                    RateConversionDocEvents.afterLineSaveBulkEvent(this, new StockEventArgs(vm.StockLineViewModel.FirstOrDefault().StockHeaderId), 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,
                    ActivityType = (int)ActivityTypeContants.MultipleCreate,
                    DocNo        = Header.DocNo,
                    DocDate      = Header.DocDate,
                    DocStatus    = Header.Status,
                }));

                return(Json(new { success = true }));
            }
            return(PartialView("_Results", vm));
        }
        public ActionResult Post(SaleDeliveryOrderSettingsViewModel vm)
        {
            SaleDeliveryOrderSettings pt = AutoMapper.Mapper.Map <SaleDeliveryOrderSettingsViewModel, SaleDeliveryOrderSettings>(vm);

            if (ModelState.IsValid)
            {
                if (vm.SaleDeliveryOrderSettingsId <= 0)
                {
                    pt.CreatedDate  = DateTime.Now;
                    pt.ModifiedDate = DateTime.Now;
                    pt.CreatedBy    = User.Identity.Name;
                    pt.ModifiedBy   = User.Identity.Name;
                    pt.ObjectState  = Model.ObjectState.Added;
                    _SaleDeliveryOrderSettingsService.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    = pt.DocTypeId,
                        DocId        = pt.SaleDeliveryOrderSettingsId,
                        ActivityType = (int)ActivityTypeContants.SettingsAdded,
                    }));


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

                    SaleDeliveryOrderSettings temp = _SaleDeliveryOrderSettingsService.Find(pt.SaleDeliveryOrderSettingsId);

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

                    temp.isVisibleDimension1   = pt.isVisibleDimension1;
                    temp.isVisibleDimension2   = pt.isVisibleDimension2;
                    temp.isVisibleDimension3   = pt.isVisibleDimension3;
                    temp.isVisibleDimension4   = pt.isVisibleDimension4;
                    temp.ImportMenuId          = pt.ImportMenuId;
                    temp.isVisibleProductUID   = pt.isVisibleProductUID;
                    temp.isMandatoryProductUID = pt.isMandatoryProductUID;
                    temp.ProcessId             = pt.ProcessId;
                    temp.filterPersonRoles     = pt.filterPersonRoles;

                    temp.ModifiedDate = DateTime.Now;
                    temp.ModifiedBy   = User.Identity.Name;
                    temp.ObjectState  = Model.ObjectState.Modified;
                    _SaleDeliveryOrderSettingsService.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       = temp.DocTypeId,
                        DocId           = temp.SaleDeliveryOrderSettingsId,
                        ActivityType    = (int)ActivityTypeContants.SettingsModified,
                        xEModifications = Modifications,
                    }));

                    return(RedirectToAction("Index", "SaleDeliveryOrderHeader", new { id = vm.DocTypeId }).Success("Data saved successfully"));
                }
            }
            //PrepareViewBag();
            return(View("Create", vm));
        }
예제 #8
0
        public ActionResult PostSummary(JobReceiveSummaryDetailViewModel vm)
        {
            //TempData["CSEXC"] = "Customize Test Exception";

            List <LogTypeViewModel> LogList = new List <LogTypeViewModel>();
            bool Modified = false;
            int  Id       = vm.JobReceiveHeaderId;

            var Header = _JobReceiveHeaderService.Find(Id);

            var JobReceives = (from p in db.JobReceiveLine
                               join t in db.JobOrderLine on p.JobOrderLineId equals t.JobOrderLineId
                               where p.JobReceiveHeaderId == Id
                               group t by new { t.ProductId, t.JobOrderHeaderId } into g
                               select g.Key).ToList();

            foreach (var item in vm.JobReceiveSummaryViewModel)
            {
                // Receive Line which has return also and return has no weight then receive weight should be 0.
                //var ReceiveWithReturnLines = from p in db.JobReceiveLine
                //                    join t in db.JobOrderLine on p.JobOrderLineId equals t.JobOrderLineId
                //                    join t2 in db.JobReceiveLineStatus on p.JobReceiveLineId equals t2.JobReceiveLineId into table
                //                    from tab in table.DefaultIfEmpty()
                //                    where t.JobOrderHeaderId == item.JobOrderHeaderId && p.PassQty > 0 && p.JobReceiveHeaderId == Id && t.ProductId == item.ProductId
                //                    && (p.PassQty - (tab.ReturnQty ?? 0)) == 0
                //                    select p;


                //foreach (var item3 in ReceiveWithReturnLines)
                //{

                //    item3.Weight = 0;
                //    item3.ObjectState = Model.ObjectState.Modified;
                //    _JobReceiveLineService.Update(item3);
                //}



                var ReceiveLines = (from p in db.JobReceiveLine
                                    join t in db.JobOrderLine on p.JobOrderLineId equals t.JobOrderLineId
                                    join t2 in db.JobReceiveLineStatus on p.JobReceiveLineId equals t2.JobReceiveLineId into table
                                    from tab in table.DefaultIfEmpty()
                                    where t.JobOrderHeaderId == item.JobOrderHeaderId && p.PassQty > 0 && p.JobReceiveHeaderId == Id && t.ProductId == item.ProductId &&
                                    (p.PassQty - (tab.ReturnQty ?? 0)) > 0
                                    select p).ToList();

                bool ValidationError = ReceiveLines.Where(m => m.Weight > 0).Any() && ReceiveLines.Where(m => m.Weight == 0).Any();

                if (ReceiveLines != null && ReceiveLines.Count > 0)
                {
                    decimal Weight = item.Weight;

                    decimal XWeight = ReceiveLines.Sum(m => m.Weight);

                    decimal PassQty = ReceiveLines.Sum(m => m.PassQty);


                    if (Weight != XWeight)
                    {
                        int     i = 0;
                        decimal WeightShortage   = 0;
                        decimal IndividualWeight = Math.Round((Weight / PassQty), 2);
                        if (i == 0 && IndividualWeight * PassQty != Weight)
                        {
                            WeightShortage = (Weight - (IndividualWeight * PassQty));
                        }

                        foreach (var item2 in ReceiveLines)
                        {
                            JobReceiveLine ExRec = new JobReceiveLine();
                            ExRec = Mapper.Map <JobReceiveLine>(item2);

                            item2.Weight       = IndividualWeight * item2.PassQty + (i == 0 ? WeightShortage : 0);
                            item2.ModifiedBy   = User.Identity.Name;
                            item2.ModifiedDate = DateTime.Now;
                            item2.ObjectState  = Model.ObjectState.Modified;

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

                            _JobReceiveLineService.Update(item2);
                            i++;

                            Modified = true;
                        }
                    }
                }
            }

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

            Header.ModifiedDate = DateTime.Now;
            Header.ObjectState  = Model.ObjectState.Modified;
            new JobReceiveHeaderService(_unitOfWork).Update(Header);

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

            try
            {
                _unitOfWork.Save();
            }

            catch (Exception ex)
            {
                string message = _exception.HandleException(ex);
                ModelState.AddModelError("", message);
                PrepareViewBag(vm.JobReceiveHeaderId);
                return(Json(new { Success = false }));
            }

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

            string RetUrl = "";


            if (Header.Status == (int)StatusConstants.Drafted || Header.Status == (int)StatusConstants.Import)
            {
                RetUrl = System.Configuration.ConfigurationManager.AppSettings["JobsDomain"] + "/JobReceiveHeader/Modify/" + Header.JobReceiveHeaderId;
            }
            else if (Header.Status == (int)StatusConstants.Submitted || Header.Status == (int)StatusConstants.ModificationSubmitted || Header.Status == (int)StatusConstants.Modified)
            {
                RetUrl = System.Configuration.ConfigurationManager.AppSettings["JobsDomain"] + "/JobReceiveHeader/ModifyAfter_Submit/" + Header.JobReceiveHeaderId;
            }
            else if (Header.Status == (int)StatusConstants.Approved || Header.Status == (int)StatusConstants.Closed)
            {
                RetUrl = System.Configuration.ConfigurationManager.AppSettings["JobsDomain"] + "/JobReceiveHeader/ModifyAfter_Approve/" + Header.JobReceiveHeaderId;
            }
            else
            {
                RetUrl = System.Configuration.ConfigurationManager.AppSettings["JobsDomain"] + "/JobReceiveHeader/Index/" + Header.DocTypeId;
            }

            return(Json(new { Success = true, Url = RetUrl }));
        }
예제 #9
0
        public ActionResult Post(JobOrderHeaderViewModel svm)
        {
            JobOrderHeader        s       = Mapper.Map <JobOrderHeaderViewModel, JobOrderHeader>(svm);
            ProdOrderCancelHeader cHeader = new ProdOrderCancelHeader();

            if (svm.JobOrderSettings != null)
            {
                if (svm.JobOrderSettings.isMandatoryCostCenter == true && (svm.CostCenterId <= 0 || svm.CostCenterId == null))
                {
                    ModelState.AddModelError("CostCenterId", "The CostCenter field is required");
                }
                if (svm.JobOrderSettings.isMandatoryMachine == true && (svm.MachineId <= 0 || svm.MachineId == null))
                {
                    ModelState.AddModelError("MachineId", "The Machine field is required");
                }
                if (svm.JobOrderSettings.isPostedInStock == true && !svm.GodownId.HasValue)
                {
                    ModelState.AddModelError("GodownId", "The Godown field is required");
                }
            }

            #region DocTypeTimeLineValidation

            try
            {
                TimePlanValidation = DocumentValidation.ValidateDocument(Mapper.Map <DocumentUniqueId>(svm), DocumentTimePlanTypeConstants.Create, 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))
            {
                List <ProdOrderHeaderListViewModel> ProdOrderIds = (List <ProdOrderHeaderListViewModel>)System.Web.HttpContext.Current.Session["ConfirmProdOrderIds"];
                bool CancelBalProdOrders = (bool)System.Web.HttpContext.Current.Session["CancelBalProdOrdrs"];
                bool CreateDyeingOrder   = ProdOrderIds.Any(m => m.Qty > 0);

                var ProdOrderLineIds = ProdOrderIds.Select(m => m.ProdOrderLineId).ToArray();

                var BalProdOrders = (from p in db.ViewProdOrderBalance.AsNoTracking()
                                     where ProdOrderLineIds.Contains(p.ProdOrderLineId)
                                     select p).ToList();

                var ProdOrderLines = (from p in db.ProdOrderLine.AsNoTracking()
                                      where ProdOrderLineIds.Contains(p.ProdOrderLineId)
                                      select p).ToList();

                var ProductIds = BalProdOrders.Select(m => m.ProductId).ToList();

                var Products = (from p in db.Product.AsNoTracking()
                                where ProductIds.Contains(p.ProductId)
                                select p).ToList();

                bool CancelQty = (from p in ProdOrderIds
                                  join t in BalProdOrders
                                  on p.ProdOrderLineId equals t.ProdOrderLineId
                                  where (t.BalanceQty - p.Qty) > 0
                                  select p).Any();
                CancelBalProdOrders = (CancelBalProdOrders && CancelQty);

                if (CreateDyeingOrder)
                {
                    s.CreatedDate   = DateTime.Now;
                    s.ModifiedDate  = DateTime.Now;
                    s.ActualDueDate = s.DueDate;
                    s.ActualDocDate = s.DocDate;
                    s.CreatedBy     = User.Identity.Name;
                    s.ModifiedBy    = User.Identity.Name;
                    s.Status        = (int)StatusConstants.Drafted;
                    _JobOrderHeaderService.Create(s);

                    new JobOrderHeaderStatusService(_unitOfWork).CreateHeaderStatus(s.JobOrderHeaderId, ref db, false);

                    if (svm.PerkViewModel != null)
                    {
                        foreach (PerkViewModel item in svm.PerkViewModel)
                        {
                            JobOrderPerk perk = Mapper.Map <PerkViewModel, JobOrderPerk>(item);
                            perk.CreatedBy        = User.Identity.Name;
                            perk.CreatedDate      = DateTime.Now;
                            perk.ModifiedBy       = User.Identity.Name;
                            perk.ModifiedDate     = DateTime.Now;
                            perk.JobOrderHeaderId = s.JobOrderHeaderId;
                            new JobOrderPerkService(_unitOfWork).Create(perk);
                        }
                    }
                }

                if (CancelBalProdOrders)
                {
                    cHeader.DocNo              = s.DocNo;
                    cHeader.DocDate            = s.DocDate;
                    cHeader.DocTypeId          = new DocumentTypeService(_unitOfWork).FindByName(TransactionDoctypeConstants.DyeingPlanCancel).DocumentTypeId;
                    cHeader.DivisionId         = s.DivisionId;
                    cHeader.SiteId             = s.SiteId;
                    cHeader.CreatedBy          = User.Identity.Name;
                    cHeader.CreatedDate        = DateTime.Now;
                    cHeader.ModifiedBy         = User.Identity.Name;
                    cHeader.ModifiedDate       = DateTime.Now;
                    cHeader.ReferenceDocId     = s.JobOrderHeaderId;
                    cHeader.ReferenceDocTypeId = s.DocTypeId;
                    cHeader.Remark             = s.Remark;
                    cHeader.ObjectState        = Model.ObjectState.Added;
                    new ProdOrderCancelHeaderService(_unitOfWork).Create(cHeader);
                }

                int Cnt = 0;

                List <HeaderChargeViewModel> HeaderCharges = new List <HeaderChargeViewModel>();
                List <LineChargeViewModel>   LineCharges   = new List <LineChargeViewModel>();
                int  pk = 0;
                bool HeaderChargeEdit = false;



                JobOrderSettings Settings = new JobOrderSettingsService(_unitOfWork).GetJobOrderSettingsForDocument(s.DocTypeId, s.DivisionId, s.SiteId);

                int?MaxLineId = new JobOrderLineChargeService(_unitOfWork).GetMaxProductCharge(s.JobOrderHeaderId, "Web.JobOrderLines", "JobOrderHeaderId", "JobOrderLineId");

                int PersonCount = 0;
                //if (!Settings.CalculationId.HasValue)
                //{
                //    throw new Exception("Calculation not configured in Job order settings");
                //}

                int CalculationId = Settings.CalculationId ?? 0;

                List <LineDetailListViewModel> LineList = new List <LineDetailListViewModel>();

                foreach (var ProdORderLineId in ProdOrderIds)
                {
                    var BalProdOrderLine = BalProdOrders.Where(m => m.ProdOrderLineId == ProdORderLineId.ProdOrderLineId).FirstOrDefault();
                    var Product          = Products.Where(m => m.ProductId == BalProdOrderLine.ProductId).FirstOrDefault();


                    if (ProdORderLineId.Qty <= BalProdOrderLine.BalanceQty && ProdORderLineId.Qty > 0)
                    {
                        if (((Settings.isVisibleRate == false || Settings.isVisibleRate == true)))
                        {
                            JobOrderLine line = new JobOrderLine();

                            if (Settings.isPostedInStock ?? false)
                            {
                                StockViewModel StockViewModel = new StockViewModel();

                                if (Cnt == 0)
                                {
                                    StockViewModel.StockHeaderId = s.StockHeaderId ?? 0;
                                }
                                else
                                {
                                    if (s.StockHeaderId != null && s.StockHeaderId != 0)
                                    {
                                        StockViewModel.StockHeaderId = (int)s.StockHeaderId;
                                    }
                                    else
                                    {
                                        StockViewModel.StockHeaderId = -1;
                                    }
                                }

                                StockViewModel.StockId            = -Cnt;
                                StockViewModel.DocHeaderId        = s.JobOrderHeaderId;
                                StockViewModel.DocLineId          = line.JobOrderLineId;
                                StockViewModel.DocTypeId          = s.DocTypeId;
                                StockViewModel.StockHeaderDocDate = s.DocDate;
                                StockViewModel.StockDocDate       = s.DocDate;
                                StockViewModel.DocNo              = s.DocNo;
                                StockViewModel.DivisionId         = s.DivisionId;
                                StockViewModel.SiteId             = s.SiteId;
                                StockViewModel.CurrencyId         = null;
                                StockViewModel.PersonId           = s.JobWorkerId;
                                StockViewModel.ProductId          = BalProdOrderLine.ProductId;
                                StockViewModel.HeaderFromGodownId = null;
                                StockViewModel.HeaderGodownId     = s.GodownId;
                                StockViewModel.HeaderProcessId    = s.ProcessId;
                                StockViewModel.GodownId           = (int)s.GodownId;
                                StockViewModel.Remark             = s.Remark;
                                StockViewModel.Status             = s.Status;
                                StockViewModel.ProcessId          = s.ProcessId;
                                StockViewModel.LotNo              = null;
                                StockViewModel.CostCenterId       = s.CostCenterId;
                                StockViewModel.Qty_Iss            = ProdORderLineId.Qty;
                                StockViewModel.Qty_Rec            = 0;
                                StockViewModel.Rate          = 0;
                                StockViewModel.ExpiryDate    = null;
                                StockViewModel.Specification = ProdOrderLines.Where(m => m.ProdOrderLineId == ProdORderLineId.ProdOrderLineId).FirstOrDefault().Specification;
                                StockViewModel.Dimension1Id  = BalProdOrderLine.Dimension1Id;
                                StockViewModel.Dimension2Id  = BalProdOrderLine.Dimension2Id;
                                StockViewModel.CreatedBy     = User.Identity.Name;
                                StockViewModel.CreatedDate   = DateTime.Now;
                                StockViewModel.ModifiedBy    = User.Identity.Name;
                                StockViewModel.ModifiedDate  = DateTime.Now;

                                string StockPostingError = "";
                                StockPostingError = new StockService(_unitOfWork).StockPost(ref StockViewModel);

                                if (StockPostingError != "")
                                {
                                    string message = StockPostingError;
                                    ModelState.AddModelError("", message);
                                    return(View("Create", svm));
                                }

                                if (Cnt == 0)
                                {
                                    s.StockHeaderId = StockViewModel.StockHeaderId;
                                }
                                line.StockId = StockViewModel.StockId;
                            }



                            if (Settings.isPostedInStockProcess ?? false)
                            {
                                StockProcessViewModel StockProcessViewModel = new StockProcessViewModel();

                                if (s.StockHeaderId != null && s.StockHeaderId != 0)//If Transaction Header Table Has Stock Header Id Then It will Save Here.
                                {
                                    StockProcessViewModel.StockHeaderId = (int)s.StockHeaderId;
                                }
                                else if (Settings.isPostedInStock ?? false)//If Stok Header is already posted during stock posting then this statement will Execute.So theat Stock Header will not generate again.
                                {
                                    StockProcessViewModel.StockHeaderId = -1;
                                }
                                else if (Cnt > 0)//If function will only post in stock process then after first iteration of loop the stock header id will go -1
                                {
                                    StockProcessViewModel.StockHeaderId = -1;
                                }
                                else//If function will only post in stock process then this statement will execute.For Example Job consumption.
                                {
                                    StockProcessViewModel.StockHeaderId = 0;
                                }
                                StockProcessViewModel.StockProcessId      = -Cnt;
                                StockProcessViewModel.DocHeaderId         = s.JobOrderHeaderId;
                                StockProcessViewModel.DocLineId           = line.JobOrderLineId;
                                StockProcessViewModel.DocTypeId           = s.DocTypeId;
                                StockProcessViewModel.StockHeaderDocDate  = s.DocDate;
                                StockProcessViewModel.StockProcessDocDate = s.DocDate;
                                StockProcessViewModel.DocNo              = s.DocNo;
                                StockProcessViewModel.DivisionId         = s.DivisionId;
                                StockProcessViewModel.SiteId             = s.SiteId;
                                StockProcessViewModel.CurrencyId         = null;
                                StockProcessViewModel.PersonId           = s.JobWorkerId;
                                StockProcessViewModel.ProductId          = BalProdOrderLine.ProductId;
                                StockProcessViewModel.HeaderFromGodownId = null;
                                StockProcessViewModel.HeaderGodownId     = s.GodownId;
                                StockProcessViewModel.HeaderProcessId    = s.ProcessId;
                                StockProcessViewModel.GodownId           = s.GodownId;
                                StockProcessViewModel.Remark             = s.Remark;
                                StockProcessViewModel.Status             = s.Status;
                                StockProcessViewModel.ProcessId          = s.ProcessId;
                                StockProcessViewModel.LotNo              = null;
                                StockProcessViewModel.CostCenterId       = s.CostCenterId;
                                StockProcessViewModel.Qty_Iss            = 0;
                                StockProcessViewModel.Qty_Rec            = ProdORderLineId.Qty;
                                StockProcessViewModel.Rate          = 0;
                                StockProcessViewModel.ExpiryDate    = null;
                                StockProcessViewModel.Specification = ProdOrderLines.Where(m => m.ProdOrderLineId == ProdORderLineId.ProdOrderLineId).FirstOrDefault().Specification;
                                StockProcessViewModel.Dimension1Id  = BalProdOrderLine.Dimension1Id;
                                StockProcessViewModel.Dimension2Id  = BalProdOrderLine.Dimension2Id;
                                StockProcessViewModel.CreatedBy     = User.Identity.Name;
                                StockProcessViewModel.CreatedDate   = DateTime.Now;
                                StockProcessViewModel.ModifiedBy    = User.Identity.Name;
                                StockProcessViewModel.ModifiedDate  = DateTime.Now;

                                string StockProcessPostingError = "";
                                StockProcessPostingError = new StockProcessService(_unitOfWork).StockProcessPost(ref StockProcessViewModel);

                                if (StockProcessPostingError != "")
                                {
                                    string message = StockProcessPostingError;
                                    ModelState.AddModelError("", message);
                                    return(PartialView("_Results", svm));
                                }


                                if ((Settings.isPostedInStock ?? false) == false)
                                {
                                    if (Cnt == 0)
                                    {
                                        s.StockHeaderId = StockProcessViewModel.StockHeaderId;
                                    }
                                }

                                line.StockProcessId = StockProcessViewModel.StockProcessId;
                            }



                            line.JobOrderHeaderId = s.JobOrderHeaderId;
                            line.ProdOrderLineId  = BalProdOrderLine.ProdOrderLineId;
                            line.ProductId        = BalProdOrderLine.ProductId;
                            line.Dimension1Id     = BalProdOrderLine.Dimension1Id;
                            line.Dimension2Id     = BalProdOrderLine.Dimension2Id;
                            line.Specification    = ProdOrderLines.Where(m => m.ProdOrderLineId == ProdORderLineId.ProdOrderLineId).FirstOrDefault().Specification;
                            line.Qty        = ProdORderLineId.Qty;
                            line.Rate       = ProdORderLineId.Rate;
                            line.DealQty    = ProdORderLineId.Qty;
                            line.UnitId     = Product.UnitId;
                            line.DealUnitId = Product.UnitId;
                            line.Amount     = (line.DealQty * line.Rate);
                            line.UnitConversionMultiplier = 1;
                            line.CreatedDate    = DateTime.Now;
                            line.ModifiedDate   = DateTime.Now;
                            line.CreatedBy      = User.Identity.Name;
                            line.ModifiedBy     = User.Identity.Name;
                            line.JobOrderLineId = pk;
                            line.Sr             = pk;
                            line.ObjectState    = Model.ObjectState.Added;
                            new JobOrderLineService(_unitOfWork).Create(line);

                            new JobOrderLineStatusService(_unitOfWork).CreateLineStatus(line.JobOrderLineId, ref db, false);

                            LineList.Add(new LineDetailListViewModel {
                                Amount = line.Amount, Rate = line.Rate, LineTableId = line.JobOrderLineId, HeaderTableId = s.JobOrderHeaderId, PersonID = s.JobWorkerId, DealQty = line.DealQty
                            });

                            pk++;
                            Cnt++;
                        }
                    }


                    if (CancelBalProdOrders && (BalProdOrderLine.BalanceQty - ProdORderLineId.Qty > 0))
                    {
                        ProdOrderCancelLine cLine = new ProdOrderCancelLine();
                        cLine.CreatedBy               = User.Identity.Name;
                        cLine.CreatedDate             = DateTime.Now;
                        cLine.ModifiedBy              = User.Identity.Name;
                        cLine.ModifiedDate            = DateTime.Now;
                        cLine.ProdOrderCancelHeaderId = cHeader.ProdOrderCancelHeaderId;
                        cLine.ProdOrderLineId         = ProdORderLineId.ProdOrderLineId;
                        cLine.Qty = (BalProdOrderLine.BalanceQty - ProdORderLineId.Qty);
                        cLine.ReferenceDocTypeId = cHeader.ReferenceDocTypeId;
                        cLine.ObjectState        = Model.ObjectState.Added;
                        new ProdOrderCancelLineService(_unitOfWork).Create(cLine);
                    }
                }

                //new JobOrderHeaderService(_unitOfWork).Update(s);

                new ChargesCalculationService(_unitOfWork).CalculateCharges(LineList, s.JobOrderHeaderId, CalculationId, MaxLineId, out LineCharges, out HeaderChargeEdit, out HeaderCharges, "Web.JobOrderHeaderCharges", "Web.JobOrderLineCharges", out PersonCount, s.DocTypeId, s.SiteId, s.DivisionId);

                //Saving Charges
                foreach (var item in LineCharges)
                {
                    JobOrderLineCharge PoLineCharge = Mapper.Map <LineChargeViewModel, JobOrderLineCharge>(item);
                    PoLineCharge.ObjectState = Model.ObjectState.Added;
                    new JobOrderLineChargeService(_unitOfWork).Create(PoLineCharge);
                }


                //Saving Header charges
                for (int i = 0; i < HeaderCharges.Count(); i++)
                {
                    if (!HeaderChargeEdit)
                    {
                        JobOrderHeaderCharge POHeaderCharge = Mapper.Map <HeaderChargeViewModel, JobOrderHeaderCharge>(HeaderCharges[i]);
                        POHeaderCharge.HeaderTableId = s.JobOrderHeaderId;
                        POHeaderCharge.PersonID      = s.JobWorkerId;
                        POHeaderCharge.ObjectState   = Model.ObjectState.Added;
                        new JobOrderHeaderChargeService(_unitOfWork).Create(POHeaderCharge);
                    }
                    else
                    {
                        var footercharge = new JobOrderHeaderChargeService(_unitOfWork).Find(HeaderCharges[i].Id);
                        footercharge.Rate   = HeaderCharges[i].Rate;
                        footercharge.Amount = HeaderCharges[i].Amount;
                        new JobOrderHeaderChargeService(_unitOfWork).Update(footercharge);
                    }
                }



                try
                {
                    _unitOfWork.Save();
                }

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

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

                System.Web.HttpContext.Current.Session.Remove("ConfirmProdOrderIds");
                System.Web.HttpContext.Current.Session.Remove("CancelBalProdOrdrs");

                if (CreateDyeingOrder)
                {
                    return(Redirect(System.Configuration.ConfigurationManager.AppSettings["JobsDomain"] + "/JobOrderHeader/Submit/" + s.JobOrderHeaderId));
                }
                else
                {
                    return(Redirect(System.Configuration.ConfigurationManager.AppSettings["JobsDomain"] + "/JobOrderHeader/Index/" + s.DocTypeId));
                }
            }

            PrepareViewBag();
            ViewBag.Mode = "Add";
            return(View("Create", svm));
        }
        public ActionResult Post(SaleEnquiryLineViewModel vm)
        {
            if (ModelState.IsValid)
            {
                List <LogTypeViewModel> LogList = new List <LogTypeViewModel>();

                SaleEnquiryLine temp = new SaleEnquiryLineService(_unitOfWork).Find(vm.SaleEnquiryLineId);

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

                temp.ProductId    = vm.ProductId;
                temp.ModifiedDate = DateTime.Now;
                temp.ModifiedBy   = User.Identity.Name;
                temp.ObjectState  = Model.ObjectState.Modified;
                new SaleEnquiryLineService(_unitOfWork).Update(temp);

                ProductBuyer PB = new ProductBuyerService(_unitOfWork).Find((int)vm.SaleToBuyerId, (int)vm.ProductId);
                if (PB == null)
                {
                    string BuyerSku = vm.BuyerSpecification.Replace("-", "") + "-" + vm.BuyerSpecification1 + "-" + vm.BuyerSpecification2;

                    ProductBuyer ProdBuyer = new ProductBuyer();
                    ProdBuyer.BuyerId             = (int)vm.SaleToBuyerId;
                    ProdBuyer.ProductId           = (int)vm.ProductId;
                    ProdBuyer.BuyerSku            = vm.BuyerSku == null ? BuyerSku : vm.BuyerSku;
                    ProdBuyer.BuyerUpcCode        = vm.BuyerUpcCode;
                    ProdBuyer.BuyerSpecification  = vm.BuyerSpecification;
                    ProdBuyer.BuyerSpecification1 = vm.BuyerSpecification1;
                    ProdBuyer.BuyerSpecification2 = vm.BuyerSpecification2;
                    ProdBuyer.BuyerSpecification3 = vm.BuyerSpecification3;
                    ProdBuyer.CreatedDate         = DateTime.Now;
                    ProdBuyer.CreatedBy           = User.Identity.Name;
                    ProdBuyer.ModifiedDate        = DateTime.Now;
                    ProdBuyer.ModifiedBy          = User.Identity.Name;
                    ProdBuyer.ObjectState         = Model.ObjectState.Added;
                    new ProductBuyerService(_unitOfWork).Create(ProdBuyer);
                }

                SaleEnquiryHeader SaleEnquiryHeader = new SaleEnquiryHeaderService(_unitOfWork).Find(temp.SaleEnquiryHeaderId);
                SaleOrderHeader   SaleOrderHeader   = new SaleOrderHeaderService(_unitOfWork).Find_ByReferenceDocId(SaleEnquiryHeader.DocTypeId, SaleEnquiryHeader.SaleEnquiryHeaderId);
                if (SaleOrderHeader == null)
                {
                    CreateSaleOrder(temp.SaleEnquiryHeaderId);
                }
                else
                {
                    CreateSaleOrderLine(temp.SaleEnquiryLineId, SaleOrderHeader.SaleOrderHeaderId);
                }

                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", vm));
                }

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

                //return RedirectToAction("Index").Success("Data saved successfully");

                //var SaleEnquiryProductMapping = _SaleEnquiryLineService.GetSaleEnquiryLineListForIndex().OrderBy(m => m.SaleEnquiryLineId).OrderBy(m => m.SaleEnquiryLineId).FirstOrDefault();

                //if (SaleEnquiryProductMapping != null)
                //{
                //    return RedirectToAction("Edit", new { id = SaleEnquiryProductMapping.SaleEnquiryLineId }).Success("Data saved successfully");
                //}
                //else
                //{
                //    return RedirectToAction("Index").Success("Data saved successfully");
                //}

                int SaleEnquiryId = _SaleEnquiryLineService.NextId(vm.SaleEnquiryLineId);

                if (SaleEnquiryId > 0)
                {
                    return(RedirectToAction("Edit", new { id = SaleEnquiryId }).Success("Data saved successfully"));
                }
                else
                {
                    return(RedirectToAction("Index").Success("Data saved successfully"));
                }
            }
            return(View("Create", vm));
        }
예제 #11
0
        public ActionResult _ResultsPost(SaleDispatchReturnMasterDetailModel vm)
        {
            int Cnt    = 0;
            int Serial = _SaleDispatchReturnLineService.GetMaxSr(vm.SaleDispatchReturnLineViewModel.FirstOrDefault().SaleDispatchReturnHeaderId);
            Dictionary <int, decimal> LineStatus = new Dictionary <int, decimal>();

            bool BeforeSave = true;

            //try
            //{
            //    BeforeSave = SaleDispatchReturnDocEvents.beforeLineSaveBulkEvent(this, new SaleEventArgs(vm.SaleDispatchReturnLineViewModel.FirstOrDefault().SaleDispatchReturnHeaderId), ref db);
            //}
            //catch (Exception ex)
            //{
            //    string message = _exception.HandleException(ex);
            //    TempData["CSEXCL"] += message;
            //    EventException = true;
            //}

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

            if (ModelState.IsValid && BeforeSave && !EventException)
            {
                int ProcessId = new ProcessService(_unitOfWork).Find(ProcessConstants.FullFinishing).ProcessId;
                SaleDispatchReturnHeader Header = new SaleDispatchReturnHeaderService(_unitOfWork).Find(vm.SaleDispatchReturnLineViewModel.FirstOrDefault().SaleDispatchReturnHeaderId);

                foreach (var item in vm.SaleDispatchReturnLineViewModel)
                {
                    decimal balqty = (from p in db.ViewSaleDispatchBalance
                                      where p.SaleDispatchLineId == item.SaleDispatchLineId
                                      select p.BalanceQty).FirstOrDefault();


                    if (item.Qty > 0 && item.Qty <= balqty)
                    {
                        SaleDispatchReturnLine Line = new SaleDispatchReturnLine();
                        Line.SaleDispatchReturnHeaderId = item.SaleDispatchReturnHeaderId;
                        Line.SaleDispatchLineId         = item.SaleDispatchLineId;
                        Line.Qty        = item.Qty;
                        Line.Sr         = Serial++;
                        Line.DealQty    = item.UnitConversionMultiplier * item.Qty;
                        Line.DealUnitId = item.DealUnitId;
                        Line.UnitConversionMultiplier = item.UnitConversionMultiplier;
                        Line.Remark       = item.Remark;
                        Line.CreatedDate  = DateTime.Now;
                        Line.ModifiedDate = DateTime.Now;
                        Line.CreatedBy    = User.Identity.Name;
                        Line.ModifiedBy   = User.Identity.Name;


                        LineStatus.Add(Line.SaleDispatchLineId, Line.Qty);


                        SaleDispatchLine SaleDispatchLine = new SaleDispatchLineService(_unitOfWork).Find(Line.SaleDispatchLineId);
                        //var receipt = new SaleDispatchLineService(_unitOfWork).Find(item.SaleDispatchLineId );



                        StockViewModel StockViewModel = new StockViewModel();

                        if (Cnt == 0)
                        {
                            StockViewModel.StockHeaderId = Header.StockHeaderId ?? 0;
                        }
                        else
                        {
                            if (Header.StockHeaderId != null && Header.StockHeaderId != 0)
                            {
                                StockViewModel.StockHeaderId = (int)Header.StockHeaderId;
                            }
                            else
                            {
                                StockViewModel.StockHeaderId = -1;
                            }
                        }

                        StockViewModel.StockId            = -Cnt;
                        StockViewModel.DocHeaderId        = Header.SaleDispatchReturnHeaderId;
                        StockViewModel.DocLineId          = Line.SaleDispatchLineId;
                        StockViewModel.DocTypeId          = Header.DocTypeId;
                        StockViewModel.StockHeaderDocDate = Header.DocDate;
                        StockViewModel.StockDocDate       = Header.DocDate;
                        StockViewModel.DocNo              = Header.DocNo;
                        StockViewModel.DivisionId         = Header.DivisionId;
                        StockViewModel.SiteId             = Header.SiteId;
                        StockViewModel.CurrencyId         = null;
                        StockViewModel.PersonId           = Header.BuyerId;
                        StockViewModel.ProductId          = item.ProductId;
                        StockViewModel.HeaderFromGodownId = null;
                        StockViewModel.HeaderGodownId     = Header.GodownId;
                        StockViewModel.HeaderProcessId    = ProcessId;
                        StockViewModel.GodownId           = Header.GodownId;
                        StockViewModel.Remark             = Header.Remark;
                        StockViewModel.Status             = Header.Status;
                        StockViewModel.ProcessId          = ProcessId;
                        StockViewModel.LotNo              = null;
                        StockViewModel.CostCenterId       = null;
                        StockViewModel.Qty_Iss            = Line.Qty;
                        StockViewModel.Qty_Rec            = 0;
                        StockViewModel.Rate          = null;
                        StockViewModel.ExpiryDate    = null;
                        StockViewModel.Specification = item.Specification;
                        StockViewModel.Dimension1Id  = item.Dimension1Id;
                        StockViewModel.Dimension2Id  = item.Dimension2Id;
                        //StockViewModel.ProductUidId = SaleDispatchLine.ProductUidId;
                        StockViewModel.CreatedBy    = User.Identity.Name;
                        StockViewModel.CreatedDate  = DateTime.Now;
                        StockViewModel.ModifiedBy   = User.Identity.Name;
                        StockViewModel.ModifiedDate = DateTime.Now;

                        string StockPostingError = "";
                        StockPostingError = new StockService(_unitOfWork).StockPostDB(ref StockViewModel, ref db);

                        if (StockPostingError != "")
                        {
                            string message = StockPostingError;
                            ModelState.AddModelError("", message);
                            return(PartialView("_Results", vm));
                        }

                        if (Cnt == 0)
                        {
                            Header.StockHeaderId = StockViewModel.StockHeaderId;
                        }

                        Line.StockId = StockViewModel.StockId;

                        Line.ObjectState = Model.ObjectState.Added;
                        db.SaleDispatchReturnLine.Add(Line);
                        //_SaleDispatchReturnLineService.Create(Line);

                        Cnt = Cnt + 1;
                    }
                }

                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.SaleDispatchReturnHeader.Add(Header);

                //new SaleDispatchReturnHeaderService(_unitOfWork).Update(Header);

                //new SaleOrderLineStatusService(_unitOfWork).UpdateSaleQtyReturnMultiple(LineStatus, Header.DocDate, ref db);

                //try
                //{
                //    SaleDispatchReturnDocEvents.onLineSaveBulkEvent(this, new SaleEventArgs(vm.SaleDispatchReturnLineViewModel.FirstOrDefault().SaleDispatchReturnHeaderId), ref db);
                //}
                //catch (Exception ex)
                //{
                //    string message = _exception.HandleException(ex);
                //    TempData["CSEXCL"] += message;
                //    EventException = true;
                //}

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

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

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

                //try
                //{
                //    SaleDispatchReturnDocEvents.afterLineSaveBulkEvent(this, new SaleEventArgs(vm.SaleDispatchReturnLineViewModel.FirstOrDefault().SaleDispatchReturnHeaderId), ref db);
                //}
                //catch (Exception ex)
                //{
                //    string message = _exception.HandleException(ex);
                //    TempData["CSEXC"] += message;
                //}

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

                return(Json(new { success = true }));
            }
            return(PartialView("_Results", vm));
        }
        public ActionResult Post(DocumentCategory vm)
        {
            DocumentCategory pt = vm;

            if (ModelState.IsValid)
            {
                if (vm.DocumentCategoryId <= 0)
                {
                    pt.ObjectState = Model.ObjectState.Added;
                    _DocumentCategoryService.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.DocumentCategory).DocumentTypeId,
                        DocId        = pt.DocumentCategoryId,
                        ActivityType = (int)ActivityTypeContants.Added,
                    }));


                    return(RedirectToAction("Create").Success("Data saved successfully"));
                }

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

                    DocumentCategory sm = _DocumentCategoryService.Find(pt.DocumentCategoryId);

                    DocumentCategory ExRec = Mapper.Map <DocumentCategory>(sm);

                    sm.DocumentCategoryName = pt.DocumentCategoryName;
                    sm.IsActive             = pt.IsActive;
                    sm.ObjectState          = Model.ObjectState.Modified;
                    _DocumentCategoryService.Update(sm);

                    LogList.Add(new LogTypeViewModel
                    {
                        ExObj = ExRec,
                        Obj   = sm,
                    });
                    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.DocumentCategory).DocumentTypeId,
                        DocId           = sm.DocumentCategoryId,
                        ActivityType    = (int)ActivityTypeContants.Modified,
                        xEModifications = Modifications,
                    }));

                    return(RedirectToAction("Index").Success("Data saved successfully"));
                }
            }
            return(View("Create", vm));
        }
예제 #13
0
        public ActionResult _CreatePost(ProcessSequenceLineViewModel svm)
        {
            ProcessSequenceLine   s    = Mapper.Map <ProcessSequenceLineViewModel, ProcessSequenceLine>(svm);
            ProcessSequenceHeader temp = new ProcessSequenceHeaderService(_unitOfWork).Find(s.ProcessSequenceHeaderId);

            //if (Command == "Submit" && (s.ProductId == 0))
            //    return RedirectToAction("Submit", "ProcessSequenceHeader", new { id = s.ProcessSequenceHeaderId }).Success("Data saved successfully");
            if (s.ProcessId == 0)
            {
                PrepareViewBag(svm);
                return(View(svm).Danger("Please fill Qty"));
            }

            if (s.Sequence == 0)
            {
                PrepareViewBag(svm);
                return(View(svm).Danger("Please fill Sequence"));
            }

            if (s.Days == 0)
            {
                PrepareViewBag(svm);
                return(View(svm).Danger("Please fill Days"));
            }

            if (ModelState.IsValid)
            {
                if (svm.ProcessSequenceLineId == 0)
                {
                    s.CreatedDate  = DateTime.Now;
                    s.ModifiedDate = DateTime.Now;
                    s.CreatedBy    = User.Identity.Name;
                    s.ModifiedBy   = User.Identity.Name;
                    s.ObjectState  = Model.ObjectState.Added;
                    _ProcessSequenceLineService.Create(s);

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

                    try
                    {
                        _unitOfWork.Save();
                    }

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

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

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

                    ProcessSequenceHeader header = new ProcessSequenceHeaderService(_unitOfWork).Find(svm.ProcessSequenceHeaderId);
                    int status = header.Status;
                    ProcessSequenceLine temp1 = _ProcessSequenceLineService.Find(svm.ProcessSequenceLineId);

                    ProcessSequenceLine ExRec = Mapper.Map <ProcessSequenceLine>(temp1);

                    temp1.ProcessId    = svm.ProcessId;
                    temp1.Sequence     = svm.Sequence;
                    temp1.Days         = svm.Days;
                    temp1.ModifiedDate = DateTime.Now;
                    temp1.ModifiedBy   = User.Identity.Name;
                    _ProcessSequenceLineService.Update(temp1);

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

                    try
                    {
                        _unitOfWork.Save();
                    }

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

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

                    return(Json(new { success = true }));
                }
            }
            PrepareViewBag(svm);
            return(PartialView("_Create", svm));
        }
        public ActionResult Post(DocumentType pt)
        {
            if (ModelState.IsValid)
            {
                if (pt.DocumentTypeId <= 0)
                {
                    pt.CreatedDate  = DateTime.Now;
                    pt.ModifiedDate = DateTime.Now;
                    pt.CreatedBy    = User.Identity.Name;
                    pt.ModifiedBy   = User.Identity.Name;
                    pt.ObjectState  = Model.ObjectState.Added;
                    _DocumentTypeService.Create(pt);

                    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.DocumentType).DocumentTypeId,
                        DocId        = pt.DocumentTypeId,
                        ActivityType = (int)ActivityTypeContants.Added,
                    }));

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

                    DocumentType temp = _DocumentTypeService.Find(pt.DocumentTypeId);

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

                    temp.DocumentTypeName      = pt.DocumentTypeName;
                    temp.DocumentTypeShortName = pt.DocumentTypeShortName;
                    temp.DocumentCategoryId    = pt.DocumentCategoryId;
                    temp.ControllerActionId    = pt.ControllerActionId;
                    temp.VoucherType           = pt.VoucherType;
                    temp.Nature          = pt.Nature;
                    temp.IconDisplayName = pt.IconDisplayName;
                    temp.ImageFileName   = pt.ImageFileName;
                    temp.DomainName      = pt.DomainName;
                    temp.ReportMenuId    = pt.ReportMenuId;
                    temp.IsActive        = pt.IsActive;
                    temp.ModifiedDate    = DateTime.Now;
                    temp.ModifiedBy      = User.Identity.Name;
                    temp.ObjectState     = Model.ObjectState.Modified;
                    _DocumentTypeService.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.DocumentType).DocumentTypeId,
                        DocId           = temp.DocumentTypeId,
                        ActivityType    = (int)ActivityTypeContants.Modified,
                        xEModifications = Modifications,
                    }));

                    return(RedirectToAction("Index").Success("Data saved successfully"));
                }
            }
            PrepareViewBag();
            return(View("Create", pt));
        }
        public ActionResult _ResultsPost(StockMasterDetailModel vm)
        {
            StockHeader         temp     = new StockHeaderService(_unitOfWork).Find(vm.StockLineViewModel.FirstOrDefault().StockHeaderId);
            StockHeaderSettings Settings = new StockHeaderSettingsService(_unitOfWork).GetStockHeaderSettingsForDocument(temp.DocTypeId, temp.DivisionId, temp.SiteId);

            bool BeforeSave = true;

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

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

            int Cnt = 0;

            if (ModelState.IsValid && BeforeSave && !EventException)
            {
                foreach (var item in vm.StockLineViewModel)
                {
                    if (item.Qty != 0 && (Settings.isMandatoryLineCostCenter == true ? item.CostCenterId.HasValue : 1 == 1))
                    {
                        StockLine line = new StockLine();
                        line.StockHeaderId = item.StockHeaderId;
                        line.Qty           = item.Qty;
                        line.ProductId     = item.ProductId;
                        line.LotNo         = item.LotNo;
                        line.Dimension1Id  = item.Dimension1Id;
                        line.Dimension2Id  = item.Dimension2Id;
                        line.Dimension3Id  = item.Dimension3Id;
                        line.Dimension4Id  = item.Dimension4Id;
                        line.CostCenterId  = item.CostCenterId;
                        line.FromProcessId = item.FromProcessId;
                        line.Specification = item.Specification;
                        line.CreatedDate   = DateTime.Now;
                        line.ModifiedDate  = DateTime.Now;
                        line.CreatedBy     = User.Identity.Name;
                        line.ModifiedBy    = User.Identity.Name;
                        line.DocNature     = (item.Qty < 0 ? StockNatureConstants.Receive : StockNatureConstants.Issue);


                        StockProcessViewModel StockProcessViewModel = new StockProcessViewModel();

                        if (temp.StockHeaderId != null && temp.StockHeaderId != 0)//If Transaction Header Table Has Stock Header Id Then It will Save Here.
                        {
                            StockProcessViewModel.StockHeaderId = (int)temp.StockHeaderId;
                        }
                        else if (Cnt > 0)//If function will only post in stock process then after first iteration of loop the stock header id will go -1
                        {
                            StockProcessViewModel.StockHeaderId = -1;
                        }
                        else//If function will only post in stock process then this statement will execute.For Example Job consumption.
                        {
                            StockProcessViewModel.StockHeaderId = 0;
                        }
                        StockProcessViewModel.StockProcessId      = -Cnt;
                        StockProcessViewModel.DocHeaderId         = temp.StockHeaderId;
                        StockProcessViewModel.DocLineId           = line.StockLineId;
                        StockProcessViewModel.DocTypeId           = temp.DocTypeId;
                        StockProcessViewModel.StockHeaderDocDate  = temp.DocDate;
                        StockProcessViewModel.StockProcessDocDate = temp.DocDate;
                        StockProcessViewModel.DocNo              = temp.DocNo;
                        StockProcessViewModel.DivisionId         = temp.DivisionId;
                        StockProcessViewModel.SiteId             = temp.SiteId;
                        StockProcessViewModel.CurrencyId         = null;
                        StockProcessViewModel.PersonId           = temp.PersonId;
                        StockProcessViewModel.ProductId          = item.ProductId;
                        StockProcessViewModel.HeaderFromGodownId = null;
                        StockProcessViewModel.HeaderGodownId     = temp.GodownId;
                        StockProcessViewModel.HeaderProcessId    = temp.ProcessId;
                        StockProcessViewModel.GodownId           = temp.GodownId;
                        StockProcessViewModel.Remark             = temp.Remark;
                        StockProcessViewModel.Status             = temp.Status;
                        StockProcessViewModel.ProcessId          = temp.ProcessId;
                        StockProcessViewModel.LotNo              = null;
                        StockProcessViewModel.CostCenterId       = item.CostCenterId;
                        //StockProcessViewModel.Qty_Iss = item.Qty;
                        //StockProcessViewModel.Qty_Rec = 0;

                        if (item.Qty > 0)
                        {
                            StockProcessViewModel.Qty_Rec = item.Qty;
                            StockProcessViewModel.Qty_Iss = 0;
                        }
                        else if (item.Qty < 0)
                        {
                            StockProcessViewModel.Qty_Rec = 0;
                            StockProcessViewModel.Qty_Iss = Math.Abs(item.Qty);
                        }

                        StockProcessViewModel.Rate          = item.Rate;
                        StockProcessViewModel.ExpiryDate    = null;
                        StockProcessViewModel.Specification = item.Specification;
                        StockProcessViewModel.Dimension1Id  = item.Dimension1Id;
                        StockProcessViewModel.Dimension2Id  = item.Dimension2Id;
                        StockProcessViewModel.Dimension3Id  = item.Dimension3Id;
                        StockProcessViewModel.Dimension4Id  = item.Dimension4Id;
                        StockProcessViewModel.CreatedBy     = User.Identity.Name;
                        StockProcessViewModel.CreatedDate   = DateTime.Now;
                        StockProcessViewModel.ModifiedBy    = User.Identity.Name;
                        StockProcessViewModel.ModifiedDate  = DateTime.Now;

                        string StockProcessPostingError = "";
                        StockProcessPostingError = new StockProcessService(_unitOfWork).StockProcessPostDB(ref StockProcessViewModel, ref db);

                        if (StockProcessPostingError != "")
                        {
                            string message = StockProcessPostingError;
                            ModelState.AddModelError("", message);
                            return(PartialView("_Results", vm));
                        }

                        line.StockProcessId = StockProcessViewModel.StockProcessId;

                        line.ObjectState = Model.ObjectState.Added;
                        db.StockLine.Add(line);
                        //_StockLineService.Create(line);
                        Cnt = Cnt + 1;
                    }
                }


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

                try
                {
                    JobConsumptionDocEvents.onLineSaveBulkEvent(this, new StockEventArgs(vm.StockLineViewModel.FirstOrDefault().StockHeaderId), 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("_Results", vm));
                }

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

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

                return(Json(new { success = true }));
            }
            return(PartialView("_Results", vm));
        }
        public ActionResult Post(PackingSettingsViewModel vm)
        {
            PackingSetting pt = AutoMapper.Mapper.Map <PackingSettingsViewModel, PackingSetting>(vm);


            if (ModelState.IsValid)
            {
                if (vm.PackingSettingId <= 0)
                {
                    pt.CreatedDate  = DateTime.Now;
                    pt.ModifiedDate = DateTime.Now;
                    pt.CreatedBy    = User.Identity.Name;
                    pt.ModifiedBy   = User.Identity.Name;
                    pt.ObjectState  = Model.ObjectState.Added;
                    _PackingSettingService.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.PackingSettingId,
                        ActivityType = (int)ActivityTypeContants.SettingsAdded,
                    }));



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

                    PackingSetting temp = _PackingSettingService.Find(pt.PackingSettingId);

                    PackingSetting ExRec = Mapper.Map <PackingSetting>(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.filterProductDivision     = pt.filterProductDivision;
                    temp.filterPersonRoles         = pt.filterPersonRoles;
                    temp.ProcessId = pt.ProcessId;
                    temp.SqlProcDocumentPrint_AfterApprove = pt.SqlProcDocumentPrint_AfterApprove;
                    temp.SqlProcDocumentPrint_AfterSubmit  = pt.SqlProcDocumentPrint_AfterSubmit;
                    temp.isVisibleProductUID  = pt.isVisibleProductUID;
                    temp.isVisibleDimension1  = pt.isVisibleDimension1;
                    temp.isVisibleDimension2  = pt.isVisibleDimension2;
                    temp.isVisibleDimension3  = pt.isVisibleDimension3;
                    temp.isVisibleDimension4  = pt.isVisibleDimension4;
                    temp.isVisibleBaleCount   = pt.isVisibleBaleCount;
                    temp.SqlProcDocumentPrint = pt.SqlProcDocumentPrint;
                    temp.ImportMenuId         = pt.ImportMenuId;
                    temp.ModifiedDate         = DateTime.Now;
                    temp.ModifiedBy           = User.Identity.Name;
                    temp.ObjectState          = Model.ObjectState.Modified;
                    _PackingSettingService.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.PackingSettingId,
                        ActivityType    = (int)ActivityTypeContants.SettingsModified,
                        xEModifications = Modifications,
                    }));

                    return(RedirectToAction("Index", "PackingHeader", new { id = vm.DocTypeId }).Success("Data saved successfully"));
                }
            }
            PrepareViewBag();
            return(View("Create", vm));
        }
        public ActionResult ConfirmedJobOrders(List <JobOrderInspectionRequestWizardViewModel> ConfirmedList, int DocTypeId, string UserRemark)
        {
            if (ConfirmedList.Count() > 0 && ConfirmedList.GroupBy(m => m.JobWorkerId).Count() > 1)
            {
                return(Json(new { Success = false, Data = " Multiple Headers are selected. " }, JsonRequestBehavior.AllowGet));
            }
            else if (ConfirmedList.Count() == 0)
            {
                return(Json(new { Success = false, Data = " No Records are selected. " }, JsonRequestBehavior.AllowGet));
            }
            else
            {
                int DivisionId = (int)System.Web.HttpContext.Current.Session["DivisionId"];
                int SiteId     = (int)System.Web.HttpContext.Current.Session["SiteId"];

                bool BeforeSave = true;
                int  Serial     = 1;
                List <JobOrderInspectionRequestLineViewModel> LineStatus = new List <JobOrderInspectionRequestLineViewModel>();

                try
                {
                    BeforeSave = JobOrderInspectionRequestDocEvents.beforeWizardSaveEvent(this, new JobEventArgs(0), ref db);
                }
                catch (Exception ex)
                {
                    string message = _exception.HandleException(ex);
                    return(Json(new { Success = false, Data = message }, JsonRequestBehavior.AllowGet));
                }


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


                int Cnt = 0;
                int Sr  = 0;


                JobOrderInspectionRequestSettings Settings = new JobOrderInspectionRequestSettingsService(db).GetJobOrderInspectionRequestSettingsForDocument(DocTypeId, DivisionId, SiteId);

                int?MaxLineId = 0;

                if (ModelState.IsValid && BeforeSave && !EventException)
                {
                    JobOrderInspectionRequestHeader pt = new JobOrderInspectionRequestHeader();

                    //Getting Settings
                    pt.SiteId       = SiteId;
                    pt.JobWorkerId  = ConfirmedList.FirstOrDefault().JobWorkerId;
                    pt.DivisionId   = DivisionId;
                    pt.ProcessId    = Settings.ProcessId;
                    pt.Remark       = UserRemark;
                    pt.DocTypeId    = DocTypeId;
                    pt.DocDate      = DateTime.Now;
                    pt.DocNo        = new DocumentTypeService(_unitOfWork).FGetNewDocNo("DocNo", ConfigurationManager.AppSettings["DataBaseSchema"] + ".JobOrderInspectionRequestHeaders", pt.DocTypeId, pt.DocDate, pt.DivisionId, pt.SiteId);
                    pt.ModifiedBy   = User.Identity.Name;
                    pt.ModifiedDate = DateTime.Now;
                    pt.CreatedBy    = User.Identity.Name;
                    pt.CreatedDate  = DateTime.Now;

                    pt.Status      = (int)StatusConstants.Drafted;
                    pt.ObjectState = Model.ObjectState.Added;

                    db.JobOrderInspectionRequestHeader.Add(pt);

                    var SelectedJobOrders = ConfirmedList;

                    var JobOrderLineIds = SelectedJobOrders.Select(m => m.JobOrderLineId).ToArray();

                    var JobOrderBalanceRecords = (from p in db.ViewJobOrderBalanceForInspectionRequest
                                                  where JobOrderLineIds.Contains(p.JobOrderLineId)
                                                  select p).AsNoTracking().ToList();

                    var JobOrderRecords = (from p in db.JobOrderLine
                                           where JobOrderLineIds.Contains(p.JobOrderLineId)
                                           select p).AsNoTracking().ToList();

                    foreach (var item in SelectedJobOrders)
                    {
                        JobOrderLine Recline    = JobOrderRecords.Where(m => m.JobOrderLineId == item.JobOrderLineId).FirstOrDefault();
                        var          balRecline = JobOrderBalanceRecords.Where(m => m.JobOrderLineId == item.JobOrderLineId).FirstOrDefault();

                        if (item.Qty <= JobOrderBalanceRecords.Where(m => m.JobOrderLineId == item.JobOrderLineId).FirstOrDefault().BalanceQty)
                        {
                            JobOrderInspectionRequestLine line = new JobOrderInspectionRequestLine();

                            line.JobOrderInspectionRequestHeaderId = pt.JobOrderInspectionRequestHeaderId;
                            line.JobOrderLineId = item.JobOrderLineId;
                            line.Qty            = item.Qty;
                            line.Remark         = item.Remark;
                            line.ProductUidId   = Recline.ProductUidId;
                            line.Sr             = Serial++;
                            line.JobOrderInspectionRequestLineId = Cnt;
                            line.CreatedDate  = DateTime.Now;
                            line.ModifiedDate = DateTime.Now;
                            line.CreatedBy    = User.Identity.Name;
                            line.ModifiedBy   = User.Identity.Name;
                            LineStatus.Add(Mapper.Map <JobOrderInspectionRequestLineViewModel>(line));

                            line.ObjectState = Model.ObjectState.Added;
                            db.JobOrderInspectionRequestLine.Add(line);
                            Cnt = Cnt + 1;
                        }
                    }

                    //new JobOrderLineStatusService(_unitOfWork).UpdateJobOrderQtyQAMultiple(LineStatus, pt.DocDate, ref db);

                    try
                    {
                        JobOrderInspectionRequestDocEvents.onWizardSaveEvent(this, new JobEventArgs(pt.JobOrderInspectionRequestHeaderId, EventModeConstants.Add), ref db);
                    }
                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        TempData["CSEXC"] += message;
                        EventException     = true;
                    }

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

                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        return(Json(new { Success = false, Data = message }, JsonRequestBehavior.AllowGet));
                    }

                    try
                    {
                        JobOrderInspectionRequestDocEvents.afterWizardSaveEvent(this, new JobEventArgs(pt.JobOrderInspectionRequestHeaderId, EventModeConstants.Add), ref db);
                    }
                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        TempData["CSEXC"] += message;
                    }

                    LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                    {
                        DocTypeId    = pt.DocTypeId,
                        DocId        = pt.JobOrderInspectionRequestHeaderId,
                        ActivityType = (int)ActivityTypeContants.WizardCreate,
                        DocNo        = pt.DocNo,
                        DocDate      = pt.DocDate,
                        DocStatus    = pt.Status,
                    }));

                    return(Json(new { Success = "URL", Data = "/JobOrderInspectionRequestHeader/Submit/" + pt.JobOrderInspectionRequestHeaderId }, JsonRequestBehavior.AllowGet));
                }

                else
                {
                    return(Json(new { Success = false, Data = "ModelState is Invalid" }, JsonRequestBehavior.AllowGet));
                }
            }
        }
        public ActionResult _CreatePost(CalculationFooterViewModel svm)
        {
            CalculationFooter s = Mapper.Map <CalculationFooterViewModel, CalculationFooter>(svm);

            if (ModelState.IsValid)
            {
                if (svm.Id <= 0)
                {
                    s.CreatedDate  = DateTime.Now;
                    s.ModifiedDate = DateTime.Now;
                    s.CreatedBy    = User.Identity.Name;
                    s.ModifiedBy   = User.Identity.Name;
                    s.ObjectState  = Model.ObjectState.Added;
                    _CalculationFooterService.Create(s);


                    try
                    {
                        _unitOfWork.Save();
                    }

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

                    return(RedirectToAction("_Create", new { CalculationID = s.CalculationId }));
                }
                else
                {
                    List <LogTypeViewModel> LogList = new List <LogTypeViewModel>();

                    CalculationFooter temp1 = _CalculationFooterService.Find(svm.Id);

                    CalculationFooter ExRec = Mapper.Map <CalculationFooter>(temp1);

                    temp1.AddDeduct               = svm.AddDeduct;
                    temp1.AffectCost              = svm.AffectCost;
                    temp1.CalculateOnId           = svm.CalculateOnId;
                    temp1.CalculationFooterLineId = svm.Id;
                    temp1.ChargeId        = svm.ChargeId;
                    temp1.RateType        = svm.RateType;
                    temp1.Amount          = svm.Amount;
                    temp1.Rate            = svm.Rate;
                    temp1.ProductChargeId = svm.ProductChargeId;
                    temp1.ChargeTypeId    = svm.ChargeTypeId;
                    temp1.CostCenterId    = svm.CostCenterId;
                    temp1.IncludedInBase  = svm.IncludedInBase;
                    temp1.IsActive        = svm.IsActive;
                    temp1.ParentChargeId  = svm.ParentChargeId;
                    temp1.ProductChargeId = svm.ProductChargeId;
                    temp1.Sr                         = svm.Sr;
                    temp1.IsVisible                  = svm.IsVisible;
                    temp1.IncludedCharges            = svm.IncludedCharges;
                    temp1.IncludedChargesCalculation = svm.IncludedChargesCalculation;
                    temp1.ModifiedDate               = DateTime.Now;
                    temp1.ModifiedBy                 = User.Identity.Name;
                    temp1.ObjectState                = Model.ObjectState.Modified;
                    _CalculationFooterService.Update(temp1);

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

                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        ModelState.AddModelError("", message);
                        PrepareViewBag(svm);
                        return(PartialView("_Create", svm));
                    }
                    // LogActivity.LogActivityDetail(new DocumentTypeService(_unitOfWork).Find(MasterDocTypeConstants.Calculation).DocumentTypeId,
                    //temp1.CalculationFooterLineId,
                    //null,
                    //(int)ActivityTypeContants.Modified,
                    //"",
                    //User.Identity.Name, "", Modifications);
                    // return Json(new { success = true });



                    LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                    {
                        DocTypeId       = new DocumentTypeService(_unitOfWork).FindByName(MasterDocTypeConstants.Calculation).DocumentTypeId,
                        DocId           = temp1.CalculationFooterLineId,
                        ActivityType    = (int)ActivityTypeContants.Modified,
                        xEModifications = Modifications,
                    }));
                }
            }
            PrepareViewBag(svm);
            return(PartialView("_Create", svm));
        }
        public ActionResult Post(ProductInvoiceGroup vm)
        {
            ProductInvoiceGroup pt = vm;

            if (ModelState.IsValid)
            {
                if (vm.ProductInvoiceGroupId <= 0)
                {
                    //pt.DivisionId = (int)System.Web.HttpContext.Current.Session["DivisionId"];
                    pt.CreatedDate  = DateTime.Now;
                    pt.ModifiedDate = DateTime.Now;
                    pt.CreatedBy    = User.Identity.Name;
                    pt.ModifiedBy   = User.Identity.Name;
                    pt.ObjectState  = Model.ObjectState.Added;
                    _ProductInvoiceGroupService.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.ProductInvoiceGroup).DocumentTypeId,
                        DocId        = pt.ProductInvoiceGroupId,
                        ActivityType = (int)ActivityTypeContants.Added,
                    }));


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

                    ProductInvoiceGroup temp = _ProductInvoiceGroupService.Find(pt.ProductInvoiceGroupId);

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

                    temp.ProductInvoiceGroupName = pt.ProductInvoiceGroupName;
                    temp.DivisionId              = pt.DivisionId;
                    temp.IsActive                = pt.IsActive;
                    temp.ItcHsCode               = pt.ItcHsCode;
                    temp.Rate                    = pt.Rate;
                    temp.Weight                  = pt.Weight;
                    temp.Knots                   = pt.Knots;
                    temp.DescriptionOfGoodsId    = pt.DescriptionOfGoodsId;
                    temp.IsSample                = pt.IsSample;
                    temp.SeparateWeightInInvoice = pt.SeparateWeightInInvoice;
                    temp.ModifiedDate            = DateTime.Now;
                    temp.ModifiedBy              = User.Identity.Name;
                    temp.ObjectState             = Model.ObjectState.Modified;
                    _ProductInvoiceGroupService.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.ProductInvoiceGroup).DocumentTypeId,
                        DocId           = temp.ProductInvoiceGroupId,
                        ActivityType    = (int)ActivityTypeContants.Modified,
                        xEModifications = Modifications,
                    }));

                    return(RedirectToAction("Index").Success("Data saved successfully"));
                }
            }

            return(View("Create", vm));
        }
예제 #20
0
        public ActionResult _CreatePost(JobReceiveQAPenaltyViewModel svm)
        {
            JobReceiveQALine    L    = new JobReceiveQALineService(db, _unitOfWork).Find(svm.JobReceiveQALineId);
            JobReceiveQAPenalty s    = Mapper.Map <JobReceiveQAPenaltyViewModel, JobReceiveQAPenalty>(svm);
            JobReceiveQAHeader  temp = new JobReceiveQAHeaderService(db).Find(L.JobReceiveQAHeaderId);

            #region BeforeSave
            bool BeforeSave = true;
            try
            {
                if (svm.JobReceiveQAPenaltyId <= 0)
                {
                    BeforeSave = JobReceiveQADocEvents.beforeLineSaveEvent(this, new JobEventArgs(svm.JobReceiveQAPenaltyId, EventModeConstants.Add), ref db);
                }
                else
                {
                    BeforeSave = JobReceiveQADocEvents.beforeLineSaveEvent(this, new JobEventArgs(svm.JobReceiveQAPenaltyId, 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.");
            }
            #endregion


            var settings = new JobReceiveQASettingsService(db).GetJobReceiveQASettingsForDocument(temp.DocTypeId, temp.DivisionId, temp.SiteId);

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



            //if (svm.JobReceiveLineId <= 0)
            //    ModelState.AddModelError("JobReceiveLineId", "The JobReceiveLine field is required");

            if (ModelState.IsValid && BeforeSave && !EventException)
            {
                if (svm.JobReceiveQAPenaltyId <= 0)
                {
                    _JobReceiveQAPenaltyService.Create(s, User.Identity.Name);



                    try
                    {
                        db.SaveChanges();
                    }

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



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

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


                    StringBuilder       logstring = new StringBuilder();
                    JobReceiveQAPenalty temp1     = _JobReceiveQAPenaltyService.Find(svm.JobReceiveQAPenaltyId);


                    JobReceiveQAPenalty ExRec = new JobReceiveQAPenalty();
                    ExRec = Mapper.Map <JobReceiveQAPenalty>(temp1);

                    temp1.ReasonId = svm.ReasonId;
                    temp1.Amount   = svm.Amount;
                    temp1.Remark   = svm.Remark;

                    _JobReceiveQAPenaltyService.Update(temp1, User.Identity.Name);

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

                    if (temp.Status != (int)StatusConstants.Drafted && temp.Status != (int)StatusConstants.Import)
                    {
                        temp.Status = (int)StatusConstants.Modified;
                    }
                    new JobReceiveQAHeaderService(db).Update(temp, User.Identity.Name);

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

                    try
                    {
                        JobReceiveQADocEvents.onLineSaveEvent(this, new JobEventArgs(temp.JobReceiveQAHeaderId, temp1.JobReceiveQAPenaltyId, 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;
                        PrepareViewBag();
                        return(PartialView("_Create", svm));
                    }

                    try
                    {
                        JobReceiveQADocEvents.afterLineSaveEvent(this, new JobEventArgs(temp.JobReceiveQAHeaderId, temp1.JobReceiveQAPenaltyId, EventModeConstants.Edit), ref db);
                    }
                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        TempData["CSEXC"] += message;
                    }

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


                    return(Json(new { success = true }));
                }
            }
            PrepareViewBag();
            return(PartialView("_Create", svm));
        }
예제 #21
0
        public ActionResult Post(Dimension4ViewModel vm)
        {
            Dimension4 pt = Mapper.Map <Dimension4ViewModel, Dimension4>(vm);

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


                    try
                    {
                        _unitOfWork.Save();
                    }

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

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

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

                    Dimension4 temp  = _Dimension4Service.Find(pt.Dimension4Id);
                    Dimension4 ExRec = Mapper.Map <Dimension4>(temp);

                    temp.Dimension4Name = pt.Dimension4Name;
                    temp.IsActive       = pt.IsActive;
                    temp.Description    = pt.Description;
                    temp.ModifiedDate   = DateTime.Now;
                    temp.ModifiedBy     = User.Identity.Name;
                    temp.ObjectState    = Model.ObjectState.Modified;
                    _Dimension4Service.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);
                        ViewBag.id   = pt.ProductTypeId;
                        ViewBag.Name = new ProductTypeService(_unitOfWork).Find(pt.ProductTypeId ?? 0).ProductTypeName;
                        return(View("Create", pt));
                    }

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

                    ViewBag.id   = pt.ProductTypeId;
                    ViewBag.Name = new ProductTypeService(_unitOfWork).Find(pt.ProductTypeId ?? 0).ProductTypeName;
                    return(RedirectToAction("Index", new { id = pt.ProductTypeId }).Success("Data saved successfully"));
                }
            }
            ViewBag.id   = vm.ProductTypeId;
            ViewBag.Name = new ProductTypeService(_unitOfWork).Find(vm.ProductTypeId ?? 0).ProductTypeName;
            return(View("Create", vm));
        }
예제 #22
0
        public ActionResult _CreatePost(ReportLine pt)
        {
            if (ModelState.IsValid)
            {
                if (pt.ReportLineId <= 0)
                {
                    pt.CreatedDate  = DateTime.Now;
                    pt.ModifiedDate = DateTime.Now;
                    pt.CreatedBy    = User.Identity.Name;
                    pt.ModifiedBy   = User.Identity.Name;
                    pt.ObjectState  = Model.ObjectState.Added;
                    _ReportLineService.Create(pt);

                    try
                    {
                        _unitOfWork.Save();
                    }
                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        ModelState.AddModelError("", message);
                        return(PartialView("_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.Added,
                    }));


                    return(RedirectToAction("_Create", new { id = pt.ReportHeaderId }));
                }
                else
                {
                    pt.ModifiedDate = DateTime.Now;
                    pt.ModifiedBy   = User.Identity.Name;
                    pt.ObjectState  = Model.ObjectState.Modified;
                    _ReportLineService.Update(pt);

                    try
                    {
                        _unitOfWork.Save();
                    }

                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        ModelState.AddModelError("", message);
                        return(PartialView("_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.Modified,
                    }));

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

            return(PartialView("_Create", pt));
        }
        public ActionResult HeaderPost(ProdOrderHeaderViewModel svm)
        {
            if (svm.DocDate > svm.DueDate)
            {
                ModelState.AddModelError("DueDate", "DueDate cannot be greater than DocDate");
            }

            #region DocTypeTimeLineValidation

            try
            {
                if (svm.ProdOrderHeaderId <= 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.ProdOrderHeaderId == 0)
                {
                    ProdOrderHeader s = Mapper.Map <ProdOrderHeaderViewModel, ProdOrderHeader>(svm);

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

                    new ProdOrderHeaderStatusService(_unitOfWork).CreateHeaderStatus(s.ProdOrderHeaderId);

                    try
                    {
                        _unitOfWork.Save();
                    }

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


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

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

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

                    //string tempredirect = (Request["Redirect"].ToString());
                    ProdOrderHeader s         = Mapper.Map <ProdOrderHeaderViewModel, ProdOrderHeader>(svm);
                    StringBuilder   logstring = new StringBuilder();
                    ProdOrderHeader temp      = _ProdOrderHeaderService.Find(s.ProdOrderHeaderId);

                    ProdOrderHeader ExRec = new ProdOrderHeader();
                    ExRec = Mapper.Map <ProdOrderHeader>(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.Remark       = s.Remark;
                    temp.DueDate      = s.DueDate;
                    temp.ModifiedDate = DateTime.Now;
                    temp.ModifiedBy   = User.Identity.Name;
                    _ProdOrderHeaderService.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.DocTypeId);
                        ViewBag.Mode = "Edit";
                        return(View("Create", svm));
                    }

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

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

                #endregion
            }
            PrepareViewBag(svm.DocTypeId);
            ViewBag.Mode = "Add";
            return(View("Create", svm));
        }
예제 #24
0
        public ActionResult _CreatePost(PersonDocument svm)
        {
            if (ModelState.IsValid)
            {
                if (svm.PersonDocumentID == 0)
                {
                    svm.CreatedDate  = DateTime.Now;
                    svm.ModifiedDate = DateTime.Now;
                    svm.CreatedBy    = User.Identity.Name;
                    svm.ModifiedBy   = User.Identity.Name;
                    svm.ObjectState  = Model.ObjectState.Added;
                    _PersonDocumentService.Create(svm);


                    try
                    {
                        _unitOfWork.Save();
                    }

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

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


                    #region

                    //Saving Images if any uploaded after UnitOfWorkSave

                    if (Request.Files.Count > 0 && Request.Files[0].ContentLength > 0)
                    {
                        //For checking the first time if the folder exists or not-----------------------------
                        string uploadfolder;
                        int    MaxLimit;
                        int.TryParse(ConfigurationManager.AppSettings["MaxFileUploadLimit"], out MaxLimit);
                        var x = (from iid in db.Counter
                                 select iid).FirstOrDefault();
                        if (x == null)
                        {
                            uploadfolder = System.Guid.NewGuid().ToString();
                            Counter img = new Counter();
                            img.ImageFolderName = uploadfolder;
                            img.ModifiedBy      = User.Identity.Name;
                            img.CreatedBy       = User.Identity.Name;
                            img.ModifiedDate    = DateTime.Now;
                            img.CreatedDate     = DateTime.Now;
                            new CounterService(_unitOfWork).Create(img);
                            _unitOfWork.Save();
                        }

                        else
                        {
                            uploadfolder = x.ImageFolderName;
                        }


                        //For checking if the image contents length is greater than 100 then create a new folder------------------------------------

                        if (!Directory.Exists(System.Web.HttpContext.Current.Request.MapPath("~/Uploads/" + uploadfolder)))
                        {
                            Directory.CreateDirectory(System.Web.HttpContext.Current.Request.MapPath("~/Uploads/" + uploadfolder));
                        }

                        int count = Directory.GetFiles(System.Web.HttpContext.Current.Request.MapPath("~/Uploads/" + uploadfolder)).Length;

                        if (count >= MaxLimit)
                        {
                            uploadfolder = System.Guid.NewGuid().ToString();
                            var u = new CounterService(_unitOfWork).Find(x.CounterId);
                            u.ImageFolderName = uploadfolder;
                            new CounterService(_unitOfWork).Update(u);
                            _unitOfWork.Save();
                        }


                        //Saving Thumbnails images:
                        Dictionary <string, string> versions = new Dictionary <string, string>();

                        //Define the versions to generate
                        versions.Add("_thumb", "maxwidth=100&maxheight=100");  //Crop to square thumbnail
                        versions.Add("_medium", "maxwidth=200&maxheight=200"); //Fit inside 400x400 area, jpeg

                        string temp2    = "";
                        string filename = System.Guid.NewGuid().ToString();
                        foreach (string filekey in System.Web.HttpContext.Current.Request.Files.Keys)
                        {
                            HttpPostedFile pfile = System.Web.HttpContext.Current.Request.Files[filekey];
                            if (pfile.ContentLength <= 0)
                            {
                                continue;                           //Skip unused file controls.
                            }
                            temp2 = Path.GetExtension(pfile.FileName);

                            string uploadFolder = System.Web.HttpContext.Current.Request.MapPath("~/Uploads/" + uploadfolder);
                            if (!Directory.Exists(uploadFolder))
                            {
                                Directory.CreateDirectory(uploadFolder);
                            }

                            string filecontent = Path.Combine(uploadFolder, svm.Name + "_" + filename);

                            //pfile.SaveAs(filecontent);
                            ImageBuilder.Current.Build(new ImageJob(pfile, filecontent, new Instructions(), false, true));


                            //Generate each version
                            foreach (string suffix in versions.Keys)
                            {
                                if (suffix == "_thumb")
                                {
                                    string tuploadFolder = System.Web.HttpContext.Current.Request.MapPath("~/Uploads/" + uploadfolder + "/Thumbs");
                                    if (!Directory.Exists(tuploadFolder))
                                    {
                                        Directory.CreateDirectory(tuploadFolder);
                                    }

                                    //Generate a filename (GUIDs are best).
                                    string tfileName = Path.Combine(tuploadFolder, svm.Name + "_" + filename);

                                    //Let the image builder add the correct extension based on the output file type
                                    //fileName = ImageBuilder.Current.Build(file, fileName, new ResizeSettings(versions[suffix]), false, true);
                                    ImageBuilder.Current.Build(new ImageJob(pfile, tfileName, new Instructions(versions[suffix]), false, true));
                                }
                                else if (suffix == "_medium")
                                {
                                    string tuploadFolder = System.Web.HttpContext.Current.Request.MapPath("~/Uploads/" + uploadfolder + "/Medium");
                                    if (!Directory.Exists(tuploadFolder))
                                    {
                                        Directory.CreateDirectory(tuploadFolder);
                                    }

                                    //Generate a filename (GUIDs are best).
                                    string tfileName = Path.Combine(tuploadFolder, svm.Name + "_" + filename);

                                    //Let the image builder add the correct extension based on the output file type
                                    //fileName = ImageBuilder.Current.Build(file, fileName, new ResizeSettings(versions[suffix]), false, true);
                                    ImageBuilder.Current.Build(new ImageJob(pfile, tfileName, new Instructions(versions[suffix]), false, true));
                                }
                            }

                            //var tempsave = _FinishedProductService.Find(pt.ProductId);

                            svm.ImageFileName   = svm.Name + "_" + filename + temp2;
                            svm.ImageFolderName = uploadfolder;
                            svm.ObjectState     = Model.ObjectState.Modified;
                            _PersonDocumentService.Update(svm);
                            _unitOfWork.Save();
                        }
                    }

                    #endregion



                    return(RedirectToAction("_Create", new { id = svm.PersonId }));
                }
                else
                {
                    svm.ModifiedBy   = User.Identity.Name;
                    svm.ModifiedDate = DateTime.Now;
                    _PersonDocumentService.Update(svm);

                    try
                    {
                        _unitOfWork.Save();
                    }

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

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

                    #region

                    //Saving Image if file is uploaded
                    if (Request.Files.Count > 0 && Request.Files[0].ContentLength > 0)
                    {
                        string uploadfolder = svm.ImageFolderName;
                        string tempfilename = svm.ImageFileName;
                        if (uploadfolder == null)
                        {
                            var x = (from iid in db.Counter
                                     select iid).FirstOrDefault();
                            if (x == null)
                            {
                                uploadfolder = System.Guid.NewGuid().ToString();
                                Counter img = new Counter();
                                img.ImageFolderName = uploadfolder;
                                img.ModifiedBy      = User.Identity.Name;
                                img.CreatedBy       = User.Identity.Name;
                                img.ModifiedDate    = DateTime.Now;
                                img.CreatedDate     = DateTime.Now;
                                new CounterService(_unitOfWork).Create(img);
                                _unitOfWork.Save();
                            }
                            else
                            {
                                uploadfolder = x.ImageFolderName;
                            }
                        }
                        //Deleting Existing Images

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

                        //Deleting Thumbnail Image:

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

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

                        //Saving Thumbnails images:
                        Dictionary <string, string> versions = new Dictionary <string, string>();

                        //Define the versions to generate
                        versions.Add("_thumb", "maxwidth=100&maxheight=100");  //Crop to square thumbnail
                        versions.Add("_medium", "maxwidth=200&maxheight=200"); //Fit inside 400x400 area, jpeg

                        string temp2    = "";
                        string filename = System.Guid.NewGuid().ToString();
                        foreach (string filekey in System.Web.HttpContext.Current.Request.Files.Keys)
                        {
                            HttpPostedFile pfile = System.Web.HttpContext.Current.Request.Files[filekey];
                            if (pfile.ContentLength <= 0)
                            {
                                continue;                           //Skip unused file controls.
                            }
                            temp2 = Path.GetExtension(pfile.FileName);

                            string uploadFolder = System.Web.HttpContext.Current.Request.MapPath("~/Uploads/" + uploadfolder);
                            if (!Directory.Exists(uploadFolder))
                            {
                                Directory.CreateDirectory(uploadFolder);
                            }

                            string filecontent = Path.Combine(uploadFolder, svm.Name + "_" + filename);

                            //pfile.SaveAs(filecontent);

                            ImageBuilder.Current.Build(new ImageJob(pfile, filecontent, new Instructions(), false, true));

                            //Generate each version
                            foreach (string suffix in versions.Keys)
                            {
                                if (suffix == "_thumb")
                                {
                                    string tuploadFolder = System.Web.HttpContext.Current.Request.MapPath("~/Uploads/" + uploadfolder + "/Thumbs");
                                    if (!Directory.Exists(tuploadFolder))
                                    {
                                        Directory.CreateDirectory(tuploadFolder);
                                    }

                                    //Generate a filename (GUIDs are best).
                                    string tfileName = Path.Combine(tuploadFolder, svm.Name + "_" + filename);

                                    //Let the image builder add the correct extension based on the output file type
                                    //fileName = ImageBuilder.Current.Build(file, fileName, new ResizeSettings(versions[suffix]), false, true);
                                    ImageBuilder.Current.Build(new ImageJob(pfile, tfileName, new Instructions(versions[suffix]), false, true));
                                }
                                else if (suffix == "_medium")
                                {
                                    string tuploadFolder = System.Web.HttpContext.Current.Request.MapPath("~/Uploads/" + uploadfolder + "/Medium");
                                    if (!Directory.Exists(tuploadFolder))
                                    {
                                        Directory.CreateDirectory(tuploadFolder);
                                    }

                                    //Generate a filename (GUIDs are best).
                                    string tfileName = Path.Combine(tuploadFolder, svm.Name + "_" + filename);

                                    //Let the image builder add the correct extension based on the output file type
                                    //fileName = ImageBuilder.Current.Build(file, fileName, new ResizeSettings(versions[suffix]), false, true);
                                    ImageBuilder.Current.Build(new ImageJob(pfile, tfileName, new Instructions(versions[suffix]), false, true));
                                }
                            }
                        }
                        var temsave = _PersonDocumentService.Find(svm.PersonDocumentID);
                        temsave.ImageFileName   = temsave.Name + "_" + filename + temp2;
                        temsave.ImageFolderName = uploadfolder;
                        _PersonDocumentService.Update(temsave);
                        _unitOfWork.Save();
                    }

                    #endregion

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

            PrepareViewBag(svm);
            return(PartialView("_Create", svm));
        }
예제 #25
0
        public ActionResult _ResultsPost(ProdOrderMasterDetailModel vm)
        {
            int Serial = _ProdOrderLineService.GetMaxSr(vm.ProdOrderLineViewModel.FirstOrDefault().ProdOrderHeaderId);
            int Pk     = 0;

            if (ModelState.IsValid)
            {
                foreach (var item in vm.ProdOrderLineViewModel)
                {
                    if (item.Qty > 0)
                    {
                        ProdOrderLine line = new ProdOrderLine();

                        line.ProdOrderHeaderId  = item.ProdOrderHeaderId;
                        line.MaterialPlanLineId = item.MaterialPlanLineId;
                        line.ProductId          = item.ProductId;
                        line.Dimension1Id       = item.Dimension1Id;
                        line.Dimension2Id       = item.Dimension2Id;
                        line.Specification      = item.Specification;
                        line.Remark             = item.Remark;
                        line.Qty             = item.Qty;
                        line.Sr              = Serial++;
                        line.ProdOrderLineId = Pk;
                        line.CreatedDate     = DateTime.Now;
                        line.ModifiedDate    = DateTime.Now;
                        line.CreatedBy       = User.Identity.Name;
                        line.ModifiedBy      = User.Identity.Name;

                        line.ObjectState = Model.ObjectState.Added;
                        _ProdOrderLineService.Create(line);

                        new ProdOrderLineStatusService(_unitOfWork).CreateLineStatus(line.ProdOrderLineId);

                        Pk++;
                    }
                }

                ProdOrderHeader Header = db.ProdOrderHeader.Find(vm.ProdOrderLineViewModel.FirstOrDefault().ProdOrderHeaderId);

                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;

                    new ProdOrderHeaderService(_unitOfWork).Update(Header);
                }

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

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

                return(Json(new { success = true }));
            }
            return(PartialView("_Results", vm));
        }
        public ActionResult _CreatePost(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;
                    new ProductBuyerService(_unitOfWork).Create(pt);

                    try
                    {
                        _unitOfWork.Save();
                    }

                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        ModelState.AddModelError("", message);
                        return(PartialView("_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 }));
                }
                else
                {
                    List <LogTypeViewModel> LogList = new List <LogTypeViewModel>();

                    ProductBuyer temp = new ProductBuyerService(_unitOfWork).Find(pt.ProductBuyerId);

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

                    temp.BuyerId             = pt.BuyerId;
                    temp.BuyerSku            = pt.BuyerSku;
                    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;
                    new ProductBuyerService(_unitOfWork).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(PartialView("_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(Json(new { success = true }));
                }
            }
            return(PartialView("_Create", vm));
        }
        public ActionResult Post(DrawBackTariffHead vm)
        {
            DrawBackTariffHead pt = vm;

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

                    ActivityLog log = new ActivityLog()
                    {
                        ActivityType = (int)(ActivityTypeContants.Added),
                        CreatedBy    = User.Identity.Name,
                        CreatedDate  = DateTime.Now,
                        DocId        = pt.DrawBackTariffHeadId,
                        Narration    = "A new DrawaBackTariffHead is created with the Id " + pt.DrawBackTariffHeadId,
                    };

                    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.DrawBackTariff).DocumentTypeId,
                        DocId        = pt.DrawBackTariffHeadId,
                        ActivityType = (int)ActivityTypeContants.Added,
                    }));

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

                    DrawBackTariffHead temp = _DrawBackTariffHeadService.Find(pt.DrawBackTariffHeadId);

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

                    temp.DrawBackTariffHeadName = pt.DrawBackTariffHeadName;
                    temp.IsActive     = pt.IsActive;
                    temp.ModifiedDate = DateTime.Now;
                    temp.ModifiedBy   = User.Identity.Name;
                    temp.ObjectState  = Model.ObjectState.Modified;
                    _DrawBackTariffHeadService.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.DrawBackTariff).DocumentTypeId,
                        DocId           = temp.DrawBackTariffHeadId,
                        ActivityType    = (int)ActivityTypeContants.Modified,
                        xEModifications = Modifications,
                    }));

                    return(RedirectToAction("Index").Success("Data saved successfully"));
                }
            }

            return(View("Create", vm));
        }
        public ActionResult Post(SaleOrderSettingsViewModel vm)
        {
            SaleOrderSettings pt = AutoMapper.Mapper.Map <SaleOrderSettingsViewModel, SaleOrderSettings>(vm);

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

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

                    try
                    {
                        _unitOfWork.Save();
                    }

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

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



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

                    SaleOrderSettings temp = _SaleOrderSettingsService.Find(pt.SaleOrderSettingsId);

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

                    temp.filterLedgerAccountGroups         = pt.filterLedgerAccountGroups;
                    temp.filterLedgerAccounts              = pt.filterLedgerAccounts;
                    temp.filterProductGroups               = pt.filterProductGroups;
                    temp.filterProducts                    = pt.filterProducts;
                    temp.filterProductTypes                = pt.filterProductTypes;
                    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.SqlProcDocumentPrint              = pt.SqlProcDocumentPrint;
                    temp.UnitConversionForId               = pt.UnitConversionForId;
                    temp.ImportMenuId               = pt.ImportMenuId;
                    temp.isVisibleAdvance           = pt.isVisibleAdvance;
                    temp.isVisibleCurrency          = pt.isVisibleCurrency;
                    temp.isVisibleDeliveryTerms     = pt.isVisibleDeliveryTerms;
                    temp.isVisibleDealUnit          = pt.isVisibleDealUnit;
                    temp.isVisibleShipMethod        = pt.isVisibleShipMethod;
                    temp.isVisibleSpecification     = pt.isVisibleSpecification;
                    temp.isVisibleProductCode       = pt.isVisibleProductCode;
                    temp.isVisiblePriority          = pt.isVisiblePriority;
                    temp.isVisibleUnitConversionFor = pt.isVisibleUnitConversionFor;
                    temp.isVisibleBillToParty       = pt.isVisibleBillToParty;
                    temp.isVisibleGodown            = pt.isVisibleGodown;
                    temp.isVisibleFinancier         = pt.isVisibleFinancier;
                    temp.isVisibleSalesExecutive    = pt.isVisibleSalesExecutive;
                    temp.isMandatoryRate            = pt.isMandatoryRate;
                    temp.isPostedInStock            = pt.isPostedInStock;
                    temp.CurrencyId      = pt.CurrencyId;
                    temp.DeliveryTermsId = pt.DeliveryTermsId;
                    temp.ShipMethodId    = pt.ShipMethodId;
                    temp.Priority        = pt.Priority;
                    temp.ProcessId       = pt.ProcessId;
                    temp.ModifiedDate    = DateTime.Now;
                    temp.ModifiedBy      = User.Identity.Name;
                    temp.ObjectState     = Model.ObjectState.Modified;
                    _SaleOrderSettingsService.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(vm);
                        return(View("Create", pt));
                    }

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

                    return(RedirectToAction("Index", "SaleOrderHeader", new { id = vm.DocTypeId }).Success("Data saved successfully"));
                }
            }
            PrepareViewBag(vm);
            return(View("Create", vm));
        }
예제 #29
0
        public ActionResult Post(FeetConversionToCms vm)
        {
            FeetConversionToCms pt = vm;

            if (ModelState.IsValid)
            {
                if (vm.FeetConversionToCmsId <= 0)
                {
                    pt.CreatedDate  = DateTime.Now;
                    pt.ModifiedDate = DateTime.Now;
                    pt.CreatedBy    = User.Identity.Name;
                    pt.ModifiedBy   = User.Identity.Name;
                    pt.ObjectState  = Model.ObjectState.Added;
                    _FeetConversionToCmsService.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.FeetConversionToCms).DocumentTypeId,
                        DocId        = pt.FeetConversionToCmsId,
                        ActivityType = (int)ActivityTypeContants.Added,
                    }));

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

                    FeetConversionToCms temp = _FeetConversionToCmsService.Find(pt.FeetConversionToCmsId);

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

                    temp.Feet         = pt.Feet;
                    temp.Inch         = pt.Inch;
                    temp.Cms          = pt.Cms;
                    temp.ModifiedDate = DateTime.Now;
                    temp.ModifiedBy   = User.Identity.Name;
                    temp.ObjectState  = Model.ObjectState.Modified;
                    _FeetConversionToCmsService.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.FeetConversionToCms).DocumentTypeId,
                        DocId           = temp.FeetConversionToCmsId,
                        ActivityType    = (int)ActivityTypeContants.Modified,
                        xEModifications = Modifications,
                    }));

                    return(RedirectToAction("Index").Success("Data saved successfully"));
                }
            }
            return(View("Create", vm));
        }
예제 #30
0
        public ActionResult Post(UnitConversionViewModel vm)
        {
            UnitConversion pt = AutoMapper.Mapper.Map <UnitConversionViewModel, UnitConversion>(vm);

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

                    try
                    {
                        _unitOfWork.Save();
                    }

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


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

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

                    UnitConversion temp  = _UnitConversionService.Find(pt.UnitConversionId);
                    UnitConversion ExRec = new UnitConversion();
                    ExRec = Mapper.Map <UnitConversion>(temp);


                    temp.FromQty             = pt.FromQty;
                    temp.FromUnitId          = pt.FromUnitId;
                    temp.ToQty               = pt.ToQty;
                    temp.ToUnitId            = pt.ToUnitId;
                    temp.UnitConversionForId = pt.UnitConversionForId;
                    temp.ModifiedDate        = DateTime.Now;
                    temp.Description         = pt.Description;
                    temp.ModifiedBy          = User.Identity.Name;
                    temp.ObjectState         = Model.ObjectState.Modified;
                    _UnitConversionService.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(pt.ProductId ?? 0);
                        return(View("Create", pt));
                    }

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

                    return(RedirectToAction("Index", new { id = vm.ProductId }).Success("Data saved successfully"));
                }
            }
            PrepareViewBag(pt.ProductId ?? 0);
            return(View("Create", vm));
        }