public void CreateLineStatus(int id)
        {
            SaleEnquiryLineExtended Stat = new SaleEnquiryLineExtended();

            Stat.SaleEnquiryLineId = id;
            Stat.ObjectState       = Model.ObjectState.Added;
            Add(Stat);
        }
Esempio n. 2
0
        public ActionResult _CreatePost(SaleEnquiryLineViewModel svm)
        {
            SaleEnquiryLine   s    = Mapper.Map <SaleEnquiryLineViewModel, SaleEnquiryLine>(svm);
            SaleEnquiryHeader temp = new SaleEnquiryHeaderService(_unitOfWork).Find(s.SaleEnquiryHeaderId);

            //if (Command == "Submit" && (s.ProductId == 0))
            //    return RedirectToAction("Submit", "SaleEnquiryHeader", new { id = s.SaleEnquiryHeaderId }).Success("Data saved successfully");

            if (svm.BuyerSpecification != null || svm.BuyerSpecification1 != null || svm.BuyerSpecification2 != null || svm.BuyerSpecification3 != null)
            {
                SaleEnquiryLine es = new SaleEnquiryLineService(_unitOfWork).Find_WithLineDetail(svm.SaleEnquiryHeaderId, svm.BuyerSpecification, svm.BuyerSpecification1, svm.BuyerSpecification2, svm.BuyerSpecification3);

                if (es != null)
                {
                    if (es != null && es.SaleEnquiryLineId != svm.SaleEnquiryLineId)
                    {
                        ModelState.AddModelError("ProductId", "This Detail is already Added !");
                    }
                }
            }



            if (svm.Qty <= 0)
            {
                //ModelState.AddModelError("Qty", "Please Check Qty");
                ViewBag.LineMode = "Create";
                string message = "Please Check Qty";
                TempData["CSEXCL"] += message;
                PrepareViewBag(temp);
                return(PartialView("_Create", svm));
            }

            if (svm.DueDate < temp.DocDate)
            {
                ModelState.AddModelError("DueDate", "DueDate greater than DocDate");
            }

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

            if (ModelState.IsValid)
            {
                if (svm.SaleEnquiryLineId <= 0)
                {
                    if (svm.BuyerSpecification != null || svm.BuyerSpecification1 != null || svm.BuyerSpecification2 != null || svm.BuyerSpecification3 != null)
                    {
                        ProductBuyer BP = new ProductBuyerService(_unitOfWork).Find(temp.SaleToBuyerId, svm.BuyerSpecification, svm.BuyerSpecification1, svm.BuyerSpecification2, svm.BuyerSpecification3);

                        if (BP != null)
                        {
                            s.ProductId = BP.ProductId;
                        }
                    }

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

                    SaleEnquiryLineExtended Extended = new SaleEnquiryLineExtended();
                    Extended.SaleEnquiryLineId   = s.SaleEnquiryLineId;
                    Extended.BuyerSpecification  = svm.BuyerSpecification;
                    Extended.BuyerSpecification1 = svm.BuyerSpecification1;
                    Extended.BuyerSpecification2 = svm.BuyerSpecification2;
                    Extended.BuyerSpecification3 = svm.BuyerSpecification3;
                    Extended.BuyerSku            = svm.BuyerSku;
                    Extended.BuyerUpcCode        = svm.BuyerUpcCode;
                    new SaleEnquiryLineExtendedService(_unitOfWork).Create(Extended);

                    //new SaleEnquiryLineStatusService(_unitOfWork).CreateLineStatus(s.SaleEnquiryLineId);

                    SaleEnquiryHeader header = new SaleEnquiryHeaderService(_unitOfWork).Find(s.SaleEnquiryHeaderId);
                    if (header.Status != (int)StatusConstants.Drafted && header.Status != (int)StatusConstants.Import)
                    {
                        header.Status       = (int)StatusConstants.Modified;
                        header.ModifiedDate = DateTime.Now;
                        header.ModifiedBy   = User.Identity.Name;
                        new SaleEnquiryHeaderService(_unitOfWork).Update(header);
                    }


                    try
                    {
                        _unitOfWork.Save();
                    }

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

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


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


                    SaleEnquiryHeader header    = new SaleEnquiryHeaderService(_unitOfWork).Find(svm.SaleEnquiryHeaderId);
                    StringBuilder     logstring = new StringBuilder();
                    int             status      = header.Status;
                    SaleEnquiryLine temp1       = _SaleEnquiryLineService.Find(svm.SaleEnquiryLineId);

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

                    //End of Tracking the Modifications::

                    temp1.DueDate                  = svm.DueDate;
                    temp1.ProductId                = svm.ProductId;
                    temp1.Specification            = svm.Specification;
                    temp1.Dimension1Id             = svm.Dimension1Id;
                    temp1.Dimension2Id             = svm.Dimension2Id;
                    temp1.Dimension3Id             = svm.Dimension3Id;
                    temp1.Dimension4Id             = svm.Dimension4Id;
                    temp1.Qty                      = svm.Qty;
                    temp1.UnitId                   = svm.UnitId;
                    temp1.DealQty                  = svm.DealQty ?? 0;
                    temp1.DealUnitId               = svm.DealUnitId;
                    temp1.UnitConversionMultiplier = svm.UnitConversionMultiplier;
                    temp1.Rate                     = svm.Rate ?? 0;
                    temp1.Amount                   = svm.Amount ?? 0;
                    temp1.Remark                   = svm.Remark;
                    temp1.ModifiedDate             = DateTime.Now;
                    temp1.ModifiedBy               = User.Identity.Name;
                    _SaleEnquiryLineService.Update(temp1);

                    SaleEnquiryLineExtended Extended = new SaleEnquiryLineExtendedService(_unitOfWork).Find(svm.SaleEnquiryLineId);
                    Extended.BuyerSpecification  = svm.BuyerSpecification;
                    Extended.BuyerSpecification1 = svm.BuyerSpecification1;
                    Extended.BuyerSpecification2 = svm.BuyerSpecification2;
                    Extended.BuyerSpecification3 = svm.BuyerSpecification3;
                    new SaleEnquiryLineExtendedService(_unitOfWork).Update(Extended);


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

                    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;
                        new SaleEnquiryHeaderService(_unitOfWork).Update(header);
                    }
                    XElement Modifications = new ModificationsCheckService().CheckChanges(LogList);
                    try
                    {
                        _unitOfWork.Save();
                    }

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

                    //Saving the Activity Log

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

                    //End of Saving the Activity Log

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

            //string messages = string.Join("; ", ModelState.Values
            //                            .SelectMany(x => x.Errors)
            //                            .Select(x => x.ErrorMessage));
            //TempData["CSEXCL"] += messages;
            ViewBag.Status = temp.Status;
            PrepareViewBag(temp);
            return(PartialView("_Create", svm));
        }
 public SaleEnquiryLineExtended Add(SaleEnquiryLineExtended pt)
 {
     _unitOfWork.Repository <SaleEnquiryLineExtended>().Insert(pt);
     return(pt);
 }
 public void Update(SaleEnquiryLineExtended pt)
 {
     pt.ObjectState = ObjectState.Modified;
     _unitOfWork.Repository <SaleEnquiryLineExtended>().Update(pt);
 }
 public void Delete(SaleEnquiryLineExtended pt)
 {
     _unitOfWork.Repository <SaleEnquiryLineExtended>().Delete(pt);
 }
 public SaleEnquiryLineExtended Create(SaleEnquiryLineExtended pt)
 {
     pt.ObjectState = ObjectState.Added;
     _unitOfWork.Repository <SaleEnquiryLineExtended>().Insert(pt);
     return(pt);
 }
        public void DeleteLineStatus(int id)
        {
            SaleEnquiryLineExtended Stat = Find(id);

            Delete(Stat);
        }