Exemplo n.º 1
0
        public ActionResult DeletePost(DispatchWaybillLineViewModel vm)
        {
            List <LogTypeViewModel> LogList = new List <LogTypeViewModel>();

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

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

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

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

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

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

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

            return(Json(new { success = true }));
        }
Exemplo n.º 2
0
        private ActionResult _Modify(int id)
        {
            DispatchWaybillLine temp = _DispatchWaybillLineService.GetDispatchWaybillLineForLineId(id);

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

            #region DocTypeTimeLineValidation
            try
            {
                TimePlanValidation = DocumentValidation.ValidateDocumentLine(new DocumentUniqueId {
                    LockReason = temp.LockReason
                }, User.Identity.Name, out ExceptionMsg, out Continue);
            }
            catch (Exception ex)
            {
                string message = _exception.HandleException(ex);
                TempData["CSEXCL"] += message;
                TimePlanValidation  = false;
            }

            if (!TimePlanValidation)
            {
                TempData["CSEXCL"] += ExceptionMsg;
            }
            #endregion

            if ((TimePlanValidation || Continue))
            {
                ViewBag.LineMode = "Edit";
            }

            DispatchWaybillHeader H = new DispatchWaybillHeaderService(_unitOfWork).GetDispatchWaybillHeader(temp.DispatchWaybillHeaderId);
            ViewBag.DocNo = H.DocNo;
            DispatchWaybillLineViewModel s = _DispatchWaybillLineService.GetDispatchWaybillLineViewModelForLineId(id);
            PrepareViewBag(s);


            return(PartialView("_Create", s));
        }
Exemplo n.º 3
0
        private ActionResult _Delete(int id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            DispatchWaybillLine DispatchWaybillLine = _DispatchWaybillLineService.GetDispatchWaybillLineForLineId(id);

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

            #region DocTypeTimeLineValidation
            try
            {
                TimePlanValidation = DocumentValidation.ValidateDocumentLine(new DocumentUniqueId {
                    LockReason = DispatchWaybillLine.LockReason
                }, User.Identity.Name, out ExceptionMsg, out Continue);
            }
            catch (Exception ex)
            {
                string message = _exception.HandleException(ex);
                TempData["CSEXCL"] += message;
                TimePlanValidation  = false;
            }

            if (!TimePlanValidation)
            {
                TempData["CSEXCL"] += ExceptionMsg;
            }
            #endregion

            if ((TimePlanValidation || Continue))
            {
                ViewBag.LineMode = "Delete";
            }

            return(View("_Create", DispatchWaybillLine));
        }
 public void Update(DispatchWaybillLine s)
 {
     s.ObjectState = ObjectState.Modified;
     _unitOfWork.Repository <DispatchWaybillLine>().Update(s);
 }
 public void Delete(DispatchWaybillLine s)
 {
     _unitOfWork.Repository <DispatchWaybillLine>().Delete(s);
 }
 public DispatchWaybillLine Create(DispatchWaybillLine S)
 {
     S.ObjectState = ObjectState.Added;
     _unitOfWork.Repository <DispatchWaybillLine>().Insert(S);
     return(S);
 }
Exemplo n.º 7
0
        public ActionResult _CreatePost(DispatchWaybillLineViewModel svm)
        {
            List <LogTypeViewModel> LogList = new List <LogTypeViewModel>();

            DispatchWaybillHeader DispatchWaybillheader = new DispatchWaybillHeaderService(_unitOfWork).Find(svm.DispatchWaybillHeaderId);

            string DataValidationMsg = DataValidation(svm);

            if (DataValidationMsg != "")
            {
                PrepareViewBag(svm);
                TempData["CSEXCL"] += DataValidationMsg;
                return(PartialView("_Create", svm));
            }

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


            if (ModelState.IsValid)
            {
                if (svm.DispatchWaybillLineId == 0)
                {
                    DispatchWaybillLine DispatchWaybillline = Mapper.Map <DispatchWaybillLineViewModel, DispatchWaybillLine>(svm);

                    DispatchWaybillline.CreatedDate  = DateTime.Now;
                    DispatchWaybillline.ModifiedDate = DateTime.Now;
                    DispatchWaybillline.CreatedBy    = User.Identity.Name;
                    DispatchWaybillline.ModifiedBy   = User.Identity.Name;
                    DispatchWaybillline.ObjectState  = Model.ObjectState.Added;
                    _DispatchWaybillLineService.Create(DispatchWaybillline);

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

                    try
                    {
                        _unitOfWork.Save();
                    }

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

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

                    return(RedirectToAction("_Create", new { id = DispatchWaybillline.DispatchWaybillHeaderId }));
                }
                else
                {
                    DispatchWaybillLine DispatchWaybillline = _DispatchWaybillLineService.GetDispatchWaybillLineForLineId(svm.DispatchWaybillLineId);
                    int status = DispatchWaybillheader.Status;

                    DispatchWaybillLine ExTempLine = new DispatchWaybillLine();
                    ExTempLine = Mapper.Map <DispatchWaybillLine>(DispatchWaybillline);


                    DispatchWaybillline.ReceiveDateTime    = svm.ReceiveDateTime;
                    DispatchWaybillline.ReceiveRemark      = svm.ReceiveRemark;
                    DispatchWaybillline.ForwardingDateTime = svm.ForwardingDateTime;
                    DispatchWaybillline.ForwardedBy        = svm.ForwardedBy;
                    DispatchWaybillline.ForwardingRemark   = svm.ForwardingRemark;
                    DispatchWaybillline.ModifiedDate       = DateTime.Now;
                    DispatchWaybillline.ModifiedBy         = User.Identity.Name;
                    _DispatchWaybillLineService.Update(DispatchWaybillline);


                    DispatchWaybillheader.Status = (int)StatusConstants.Modified;
                    new DispatchWaybillHeaderService(_unitOfWork).Update(DispatchWaybillheader);

                    LogList.Add(new LogTypeViewModel
                    {
                        ExObj = ExTempLine,
                        Obj   = DispatchWaybillline
                    });

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

                    try
                    {
                        _unitOfWork.Save();
                    }

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

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

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

            ViewBag.Status = DispatchWaybillheader.Status;
            PrepareViewBag(svm);
            return(PartialView("_Create", svm));
        }
        public ActionResult Create(DispatchWaybillHeaderViewModel svm)
        {
            string DataValidationMsg = DataValidation(svm);

            if (DataValidationMsg != "")
            {
                PrepareViewBag(svm);
                PrepareViewBag(svm.DocTypeId);
                return(View(svm).Danger(DataValidationMsg));
            }

            #region DocTypeTimeLineValidation

            try
            {
                if (svm.DispatchWaybillHeaderId <= 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.DispatchWaybillHeaderId == 0)
                {
                    DispatchWaybillHeader DispatchWaybillHeader = Mapper.Map <DispatchWaybillHeaderViewModel, DispatchWaybillHeader>(svm);
                    DispatchWaybillHeader.CreatedDate  = DateTime.Now;
                    DispatchWaybillHeader.ModifiedDate = DateTime.Now;
                    DispatchWaybillHeader.CreatedBy    = User.Identity.Name;
                    DispatchWaybillHeader.ModifiedBy   = User.Identity.Name;
                    DispatchWaybillHeader.Status       = (int)StatusConstants.Drafted;

                    if (svm.DocTypeId == new DocumentTypeService(_unitOfWork).Find(TransactionDoctypeConstants.PreDispatchWaybill).DocumentTypeId)
                    {
                        DispatchWaybillHeader.IsPreCarriage = true;
                    }
                    else
                    {
                        DispatchWaybillHeader.IsPreCarriage = false;
                    }


                    _DispatchWaybillHeaderService.Create(DispatchWaybillHeader);


                    var routecities = new RouteLineService(_unitOfWork).GetRouteLineListForIndex(svm.RouteId).ToList();

                    foreach (var item in routecities)
                    {
                        DispatchWaybillLine DispatchWaybillLine = new DispatchWaybillLine();
                        DispatchWaybillLine.CityId       = item.CityId;
                        DispatchWaybillLine.CreatedDate  = DateTime.Now;
                        DispatchWaybillLine.ModifiedDate = DateTime.Now;
                        DispatchWaybillLine.CreatedBy    = User.Identity.Name;
                        DispatchWaybillLine.ModifiedBy   = User.Identity.Name;
                        new DispatchWaybillLineService(_unitOfWork).Create(DispatchWaybillLine);
                    }

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

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

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

                #region EditRecord
                else
                {
                    int routeid = _DispatchWaybillHeaderService.GetDispatchWaybillHeaderViewModel(svm.DispatchWaybillHeaderId).RouteId;

                    DispatchWaybillHeader DispatchWaybillHeader = Mapper.Map <DispatchWaybillHeaderViewModel, DispatchWaybillHeader>(svm);

                    int status = DispatchWaybillHeader.Status;

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

                    DispatchWaybillHeader.Status       = (int)StatusConstants.Modified;
                    DispatchWaybillHeader.ModifiedDate = DateTime.Now;
                    DispatchWaybillHeader.ModifiedBy   = User.Identity.Name;
                    _DispatchWaybillHeaderService.Update(DispatchWaybillHeader);



                    if (routeid != svm.RouteId)
                    {
                        var dispatchwaybillline = new DispatchWaybillLineService(_unitOfWork).GetDispatchWaybillLineForHeaderId(svm.DispatchWaybillHeaderId);

                        foreach (var item in dispatchwaybillline)
                        {
                            new DispatchWaybillLineService(_unitOfWork).Delete(item.DispatchWaybillLineId);
                        }


                        var routecities = new RouteLineService(_unitOfWork).GetRouteLineListForIndex(svm.RouteId).ToList();

                        foreach (var item in routecities)
                        {
                            DispatchWaybillLine DispatchWaybillLine = new DispatchWaybillLine();
                            DispatchWaybillLine.DispatchWaybillHeaderId = DispatchWaybillHeader.DispatchWaybillHeaderId;
                            DispatchWaybillLine.CityId       = item.CityId;
                            DispatchWaybillLine.CreatedDate  = DateTime.Now;
                            DispatchWaybillLine.ModifiedDate = DateTime.Now;
                            DispatchWaybillLine.CreatedBy    = User.Identity.Name;
                            DispatchWaybillLine.ModifiedBy   = User.Identity.Name;
                            new DispatchWaybillLineService(_unitOfWork).Create(DispatchWaybillLine);
                        }
                    }

                    try
                    {
                        _unitOfWork.Save();
                    }

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

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

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