Exemple #1
0
        // GET: /PurchaseOrderSettingMaster/Create

        public ActionResult Create(int id)//DocTypeId
        {
            List <string> UserRoles = (List <string>)System.Web.HttpContext.Current.Session["Roles"];

            if (!UserRoles.Contains("SysAdmin"))
            {
                return(View("~/Views/Shared/InValidSettings.cshtml"));
            }
            var DivisionId = (int)System.Web.HttpContext.Current.Session["DivisionId"];
            var SiteId     = (int)System.Web.HttpContext.Current.Session["SiteId"];
            //PrepareViewBag();
            var settings = new PurchaseOrderSettingService(_unitOfWork).GetPurchaseOrderSettingForDocument(id, DivisionId, SiteId);

            if (settings == null)
            {
                PurchaseOrderSettingsViewModel vm = new PurchaseOrderSettingsViewModel();
                vm.DocTypeName = new DocumentTypeService(_unitOfWork).Find(id).DocumentTypeName;
                vm.SiteId      = SiteId;
                vm.DivisionId  = DivisionId;
                vm.DocTypeId   = id;
                return(View("Create", vm));
            }
            else
            {
                PurchaseOrderSettingsViewModel temp = AutoMapper.Mapper.Map <PurchaseOrderSetting, PurchaseOrderSettingsViewModel>(settings);
                temp.DocTypeName = new DocumentTypeService(_unitOfWork).Find(id).DocumentTypeName;
                return(View("Create", temp));
            }
        }
Exemple #2
0
        public ActionResult Post(PurchaseOrderSettingsViewModel vm)
        {
            PurchaseOrderSetting pt = AutoMapper.Mapper.Map <PurchaseOrderSettingsViewModel, PurchaseOrderSetting>(vm);

            if (!pt.CalculationId.HasValue)
            {
                ModelState.AddModelError("CalculationId", "The Calculation field is required");
            }

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

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


                    try
                    {
                        _unitOfWork.Save();
                    }

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


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

                    PurchaseOrderSetting temp = _PurchaseOrderSettingService.Find(pt.PurchaseOrderSettingId);

                    PurchaseOrderSetting ExRec = Mapper.Map <PurchaseOrderSetting>(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.isEditableRate                    = pt.isEditableRate;
                    temp.filterContraDivisions             = pt.filterContraDivisions;
                    temp.filterContraSites                 = pt.filterContraSites;
                    temp.isMandatoryCostCenter             = pt.isMandatoryCostCenter;
                    temp.isMandatoryRate                   = pt.isMandatoryRate;
                    temp.CalculationId                     = pt.CalculationId;
                    temp.SqlProcGenProductUID              = pt.SqlProcGenProductUID;
                    temp.SqlProcDocumentPrint_AfterApprove = pt.SqlProcDocumentPrint_AfterApprove;
                    temp.SqlProcDocumentPrint_AfterSubmit  = pt.SqlProcDocumentPrint_AfterSubmit;
                    temp.isPostedInStockVirtual            = pt.isPostedInStockVirtual;
                    temp.isVisibleCostCenter               = pt.isVisibleCostCenter;
                    temp.isVisibleDimension1               = pt.isVisibleDimension1;
                    temp.isVisibleDimension2               = pt.isVisibleDimension2;
                    temp.isVisibleDimension3               = pt.isVisibleDimension3;
                    temp.isVisibleDimension4               = pt.isVisibleDimension4;
                    temp.TermsAndConditions                = pt.TermsAndConditions;
                    temp.isVisibleLotNo                    = pt.isVisibleLotNo;
                    temp.SqlProcDocumentPrint              = pt.SqlProcDocumentPrint;
                    temp.CalculateDiscountOnRate           = pt.CalculateDiscountOnRate;
                    temp.isAllowedWithoutQuotation         = pt.isAllowedWithoutQuotation;

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


                    return(RedirectToAction("Index", "PurchaseOrderHeader", new { id = vm.DocTypeId }).Success("Data saved successfully"));
                }
            }
            //PrepareViewBag();
            return(View("Create", vm));
        }