Beispiel #1
0
        public ActionResult _CreatePost(ProcessSequenceLineViewModel svm)
        {
            ProcessSequenceLine   s    = Mapper.Map <ProcessSequenceLineViewModel, ProcessSequenceLine>(svm);
            ProcessSequenceHeader temp = (from p in db.ProcessSequenceHeader
                                          where p.ProcessSequenceHeaderId == svm.ProcessSequenceHeaderId
                                          select p).FirstOrDefault();

            ProductCollection PColl = new ProductCollectionService(_unitOfWork).Find(svm.RefDocId.Value);


            if (ModelState.IsValid)
            {
                if (svm.ProcessSequenceLineId <= 0)
                {
                    if (temp == null)
                    {
                        int RefDocTypeId = new DocumentTypeService(_unitOfWork).Find(MasterDocTypeConstants.ProductCollection).DocumentTypeId;

                        ProcessSequenceHeader Header = new ProcessSequenceHeader();
                        Header.ProcessSequenceHeaderName = PColl.ProductCollectionName + "-" + new DivisionService(_unitOfWork).Find((int)HttpContext.Session["DivisionId"]).DivisionName;
                        Header.ReferenceDocTypeId        = RefDocTypeId;
                        Header.ReferenceDocId            = PColl.ProductCollectionId;
                        Header.CreatedBy    = User.Identity.Name;
                        Header.CreatedDate  = DateTime.Now;
                        Header.ModifiedBy   = User.Identity.Name;
                        Header.ModifiedDate = DateTime.Now;
                        Header.ObjectState  = Model.ObjectState.Added;

                        new ProcessSequenceHeaderService(_unitOfWork).Create(Header);

                        s.ProcessSequenceHeaderId = Header.ProcessSequenceHeaderId;
                    }
                    else
                    {
                        s.ProcessSequenceHeaderId = temp.ProcessSequenceHeaderId;
                    }

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

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

                    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("_CreateForProductCollection", new { id = svm.RefDocId }));
                }
                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.ProductRateGroupId = svm.ProductRateGroupId;
                    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           = temp.ProcessSequenceHeaderId,
                        DocLineId       = temp1.ProcessSequenceLineId,
                        ActivityType    = (int)ActivityTypeContants.Modified,
                        xEModifications = Modifications,
                    }));

                    return(Json(new { success = true }));
                }
            }
            PrepareViewBag(svm);
            return(PartialView("_Create", svm));
        }
Beispiel #2
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));
        }