Пример #1
0
        // GET: /PurchaseOrderCancelHeaderMaster/Create

        public ActionResult Create(int id)//DocumentTypeId
        {
            PrepareViewBag(id);
            PurchaseOrderCancelHeaderViewModel vm = new PurchaseOrderCancelHeaderViewModel();

            vm.DivisionId  = (int)System.Web.HttpContext.Current.Session["DivisionId"];
            vm.SiteId      = (int)System.Web.HttpContext.Current.Session["SiteId"];
            vm.CreatedDate = DateTime.Now;

            //Getting Settings
            var settings = new PurchaseOrderSettingService(_unitOfWork).GetPurchaseOrderSettingForDocument(id, vm.DivisionId, vm.SiteId);

            if (settings == null && UserRoles.Contains("SysAdmin"))
            {
                return(RedirectToAction("CreatePurchaseOrderCancel", "PurchaseOrderSetting", new { id = id }).Warning("Please create Purchase Order Cancel settings"));
            }
            else if (settings == null && !UserRoles.Contains("SysAdmin"))
            {
                return(View("~/Views/Shared/InValidSettings.cshtml"));
            }
            vm.PurchaseOrderSettings = Mapper.Map <PurchaseOrderSetting, PurchaseOrderSettingsViewModel>(settings);
            vm.DocDate   = DateTime.Now;
            vm.DocTypeId = id;
            vm.DocNo     = new DocumentTypeService(_unitOfWork).FGetNewDocNo("DocNo", ConfigurationManager.AppSettings["DataBaseSchema"] + ".PurchaseOrderCancelHeaders", vm.DocTypeId, vm.DocDate, vm.DivisionId, vm.SiteId);
            ViewBag.Mode = "Add";
            return(View("Create", vm));
        }
        public ActionResult Create(int id)//DocumentTypeId
        {
            PrepareViewBag(id);
            PurchaseOrderCancelHeaderViewModel vm = new PurchaseOrderCancelHeaderViewModel();

            vm.DivisionId = (int)System.Web.HttpContext.Current.Session["DivisionId"];
            vm.SiteId     = (int)System.Web.HttpContext.Current.Session["SiteId"];

            //Getting Settings
            var settings = new PurchaseOrderSettingService(_unitOfWork).GetPurchaseOrderSettingForDocument(id, vm.DivisionId, vm.SiteId);

            vm.PurchaseOrderSettings = Mapper.Map <PurchaseOrderSetting, PurchaseOrderSettingsViewModel>(settings);
            vm.DocTypeId             = id;
            vm.DocDate   = DateTime.Now;
            vm.DocNo     = new DocumentTypeService(_unitOfWork).FGetNewDocNo("DocNo", ConfigurationManager.AppSettings["DataBaseSchema"] + ".PurchaseOrderCancelHeaders", vm.DocTypeId, vm.DocDate, vm.DivisionId, vm.SiteId);
            ViewBag.Mode = "Add";
            return(View("Create", vm));
        }
Пример #3
0
        public ActionResult Detail(int id, string IndexType, string transactionType)
        {
            ViewBag.transactionType = transactionType;
            ViewBag.IndexStatus     = IndexType;

            PurchaseOrderCancelHeader          pt   = _PurchaseOrderCancelHeaderService.Find(id);
            PurchaseOrderCancelHeaderViewModel temp = AutoMapper.Mapper.Map <PurchaseOrderCancelHeader, PurchaseOrderCancelHeaderViewModel>(pt);

            //Job Order Settings
            var settings = new PurchaseOrderSettingService(_unitOfWork).GetPurchaseOrderSettingForDocument(pt.DocTypeId, pt.DivisionId, pt.SiteId);

            if (settings == null && UserRoles.Contains("SysAdmin"))
            {
                return(RedirectToAction("CreatePurchaseOrderCancel", "PurchaseOrderSetting", new { id = pt.DocTypeId }).Warning("Please create Purchase Order Cancel settings"));
            }
            else if (settings == null && !UserRoles.Contains("SysAdmin"))
            {
                return(View("~/Views/Shared/InValidSettings.cshtml"));
            }
            temp.PurchaseOrderSettings = Mapper.Map <PurchaseOrderSetting, PurchaseOrderSettingsViewModel>(settings);
            PrepareViewBag(pt.DocTypeId);
            if (pt == null)
            {
                return(HttpNotFound());
            }

            if (String.IsNullOrEmpty(transactionType) || transactionType == "detail")
            {
                LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                {
                    DocTypeId    = pt.DocTypeId,
                    DocId        = pt.PurchaseOrderCancelHeaderId,
                    ActivityType = (int)ActivityTypeContants.Detail,
                    DocNo        = pt.DocNo,
                    DocDate      = pt.DocDate,
                    DocStatus    = pt.Status,
                }));
            }

            return(View("Create", temp));
        }
        public ActionResult OrderCancelWizard(int id)//DocumentTypeId
        {
            PrepareViewBag(id);
            PurchaseOrderCancelHeaderViewModel vm = new PurchaseOrderCancelHeaderViewModel();

            vm.DivisionId      = (int)System.Web.HttpContext.Current.Session["DivisionId"];
            vm.SiteId          = (int)System.Web.HttpContext.Current.Session["SiteId"];
            ViewBag.ReasonList = new ReasonService(_unitOfWork).GetReasonList(TransactionDocCategoryConstants.PurchaseOrderCancel).ToList();
            //Getting Settings
            var settings = new PurchaseOrderSettingService(_unitOfWork).GetPurchaseOrderSettingForDocument(id, vm.DivisionId, vm.SiteId);

            if (settings == null && UserRoles.Contains("SysAdmin"))
            {
                return(RedirectToAction("CreatePurchaseOrderCancel", "PurchaseOrderSettings", new { id = id }).Warning("Please create Purchase order cancel settings"));
            }
            else if (settings == null && !UserRoles.Contains("SysAdmin"))
            {
                return(View("~/Views/Shared/InValidSettings.cshtml"));
            }
            return(View());
        }
Пример #5
0
        // GET: /ProductMaster/Edit/5

        private ActionResult Edit(int id, string IndexType)
        {
            ViewBag.IndexStatus = IndexType;

            PurchaseOrderCancelHeader pt = _PurchaseOrderCancelHeaderService.Find(id);

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

            #region DocTypeTimeLineValidation
            try
            {
                TimePlanValidation = DocumentValidation.ValidateDocument(Mapper.Map <DocumentUniqueId>(pt), 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

            PurchaseOrderCancelHeaderViewModel temp = AutoMapper.Mapper.Map <PurchaseOrderCancelHeader, PurchaseOrderCancelHeaderViewModel>(pt);

            if ((!TimePlanValidation && !Continue))
            {
                return(RedirectToAction("DetailInformation", new { id = id, IndexType = IndexType }));
            }

            //Job Order Settings
            var settings = new PurchaseOrderSettingService(_unitOfWork).GetPurchaseOrderSettingForDocument(pt.DocTypeId, pt.DivisionId, pt.SiteId);

            if (settings == null && UserRoles.Contains("SysAdmin"))
            {
                return(RedirectToAction("CreatePurchaseOrderCancel", "PurchaseOrderSetting", new { id = pt.DocTypeId }).Warning("Please create Purchase Order Cancel settings"));
            }
            else if (settings == null && !UserRoles.Contains("SysAdmin"))
            {
                return(View("~/Views/Shared/InValidSettings.cshtml"));
            }
            temp.PurchaseOrderSettings = Mapper.Map <PurchaseOrderSetting, PurchaseOrderSettingsViewModel>(settings);
            PrepareViewBag(pt.DocTypeId);
            ViewBag.Mode = "Edit";

            if (!(System.Web.HttpContext.Current.Request.UrlReferrer.PathAndQuery).Contains("Create"))
            {
                LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                {
                    DocTypeId    = pt.DocTypeId,
                    DocId        = pt.PurchaseOrderCancelHeaderId,
                    ActivityType = (int)ActivityTypeContants.Detail,
                    DocNo        = pt.DocNo,
                    DocDate      = pt.DocDate,
                    DocStatus    = pt.Status,
                }));
            }

            return(View("Create", temp));
        }
Пример #6
0
        public ActionResult Post(PurchaseOrderCancelHeaderViewModel vm)
        {
            #region BeforeSave
            bool BeforeSave = true;
            try
            {
                if (vm.PurchaseOrderCancelHeaderId <= 0)
                {
                    BeforeSave = PurchaseOrderCancelDocEvents.beforeHeaderSaveEvent(this, new PurchaseEventArgs(vm.PurchaseOrderCancelHeaderId, EventModeConstants.Add), ref db);
                }
                else
                {
                    BeforeSave = PurchaseOrderCancelDocEvents.beforeHeaderSaveEvent(this, new PurchaseEventArgs(vm.PurchaseOrderCancelHeaderId, EventModeConstants.Edit), ref db);
                }
            }
            catch (Exception ex)
            {
                string message = _exception.HandleException(ex);
                TempData["CSEXC"] += message;
                EventException     = true;
            }
            if (!BeforeSave)
            {
                TempData["CSEXC"] += "Failed validation before save";
            }
            #endregion


            #region DocTypeTimeLineValidation

            try
            {
                if (vm.PurchaseOrderCancelHeaderId <= 0)
                {
                    TimePlanValidation = DocumentValidation.ValidateDocument(Mapper.Map <DocumentUniqueId>(vm), DocumentTimePlanTypeConstants.Create, User.Identity.Name, out ExceptionMsg, out Continue);
                }
                else
                {
                    TimePlanValidation = DocumentValidation.ValidateDocument(Mapper.Map <DocumentUniqueId>(vm), 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

            PurchaseOrderCancelHeader pt = AutoMapper.Mapper.Map <PurchaseOrderCancelHeaderViewModel, PurchaseOrderCancelHeader>(vm);

            if (vm.SupplierId == 0)
            {
                ModelState.AddModelError("SupplierId", "The Supplier field is required");
            }

            if (ModelState.IsValid && BeforeSave && !EventException && (TimePlanValidation || Continue))
            {
                #region CreateRecord
                if (vm.PurchaseOrderCancelHeaderId <= 0)
                {
                    pt.Status       = (int)StatusConstants.Drafted;
                    pt.CreatedDate  = DateTime.Now;
                    pt.ModifiedDate = DateTime.Now;
                    pt.CreatedBy    = User.Identity.Name;
                    pt.ModifiedBy   = User.Identity.Name;
                    pt.ObjectState  = Model.ObjectState.Added;
                    db.PurchaseOrderCancelHeader.Add(pt);
                    //_PurchaseOrderCancelHeaderService.Create(pt);

                    try
                    {
                        PurchaseOrderCancelDocEvents.onHeaderSaveEvent(this, new PurchaseEventArgs(pt.PurchaseOrderCancelHeaderId, 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);
                        TempData["CSEXC"] += message;
                        PrepareViewBag(vm.DocTypeId);
                        ViewBag.Mode = "Add";
                        return(View("Create", vm));
                    }

                    try
                    {
                        PurchaseOrderCancelDocEvents.afterHeaderSaveEvent(this, new PurchaseEventArgs(pt.PurchaseOrderCancelHeaderId, 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.PurchaseOrderCancelHeaderId,
                        ActivityType = (int)ActivityTypeContants.Added,
                        DocNo        = pt.DocNo,
                        DocDate      = pt.DocDate,
                        DocStatus    = pt.Status,
                    }));

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

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

                    PurchaseOrderCancelHeader temp = _PurchaseOrderCancelHeaderService.Find(pt.PurchaseOrderCancelHeaderId);

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

                    int status = temp.Status;

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

                    temp.DocDate      = pt.DocDate;
                    temp.DocNo        = pt.DocNo;
                    temp.ReasonId     = pt.ReasonId;
                    temp.Remark       = pt.Remark;
                    temp.SiteId       = pt.SiteId;
                    temp.SupplierId   = pt.SupplierId;
                    temp.ModifiedDate = DateTime.Now;
                    temp.ModifiedBy   = User.Identity.Name;
                    temp.ObjectState  = Model.ObjectState.Modified;
                    //_PurchaseOrderCancelHeaderService.Update(temp);
                    db.PurchaseOrderCancelHeader.Add(temp);

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

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

                    try
                    {
                        PurchaseOrderCancelDocEvents.onHeaderSaveEvent(this, new PurchaseEventArgs(temp.PurchaseOrderCancelHeaderId, EventModeConstants.Edit), ref db);
                    }
                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        TempData["CSEXC"] += message;
                        EventException     = true;
                    }

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

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

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

                    try
                    {
                        PurchaseOrderCancelDocEvents.afterHeaderSaveEvent(this, new PurchaseEventArgs(temp.PurchaseOrderCancelHeaderId, 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.PurchaseOrderCancelHeaderId,
                        ActivityType    = (int)ActivityTypeContants.Modified,
                        DocNo           = temp.DocNo,
                        xEModifications = Modifications,
                        DocDate         = temp.DocDate,
                        DocStatus       = temp.Status,
                    }));

                    return(RedirectToAction("Index", new { id = vm.DocTypeId }).Success("Data saved successfully"));
                }
                #endregion
            }
            PrepareViewBag(vm.DocTypeId);
            ViewBag.Mode = "Add";
            return(View("Create", vm));
        }