// GET: /ProductMaster/Edit/5

        public ActionResult Edit(int id)//ProductBuyerId
        {
            int DivisionId = (int)System.Web.HttpContext.Current.Session["DivisionId"];
            int SiteId     = (int)System.Web.HttpContext.Current.Session["SiteId"];
            ProductBuyerSettings Settings = new ProductBuyerSettingsService(_unitOfWork).GetProductBuyerSettings(DivisionId, SiteId);

            List <string> UserRoles = new List <string>();

            UserRoles = (List <string>)System.Web.HttpContext.Current.Session["Roles"];

            if (Settings == null && UserRoles.Contains("SysAdmin"))
            {
                return(RedirectToAction("Create", "ProductBuyerSettings").Warning("Please create Product Buyer settings"));
            }
            else if (Settings == null && !UserRoles.Contains("SysAdmin"))
            {
                return(View("~/Views/Shared/InValidSettings.cshtml"));
            }

            ProductBuyer          pt = _ProductBuyerService.Find(id);
            ProductBuyerViewModel vm = AutoMapper.Mapper.Map <ProductBuyer, ProductBuyerViewModel>(pt);

            if (pt == null)
            {
                return(HttpNotFound());
            }
            Product temp = new ProductService(_unitOfWork).Find(pt.ProductId);

            ViewBag.Name            = temp.ProductName;
            ViewBag.Id              = pt.ProductId;
            vm.ProductBuyerSettings = Mapper.Map <ProductBuyerSettings, ProductBuyerSettingsViewModel>(Settings);;
            return(View("Create", vm));
        }
        // GET: /ProductMaster/Edit/5

        public ActionResult Edit(int id)//ProductBuyerId
        {
            ProductBuyer          pt = _ProductBuyerService.Find(id);
            ProductBuyerViewModel vm = AutoMapper.Mapper.Map <ProductBuyer, ProductBuyerViewModel>(pt);

            if (pt == null)
            {
                return(HttpNotFound());
            }
            Product temp = new ProductService(_unitOfWork).Find(pt.ProductId);

            ViewBag.Name = temp.ProductName;
            ViewBag.Id   = pt.ProductId;
            return(View("Create", vm));
        }
        // GET: /ProductMaster/Delete/5

        public ActionResult Delete(int id)//ProductBuyer Id
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ProductBuyer ProductBuyer = db.ProductBuyer.Find(id);

            if (ProductBuyer == null)
            {
                return(HttpNotFound());
            }
            ReasonViewModel vm = new ReasonViewModel()
            {
                id = id,
            };

            return(PartialView("_Reason", vm));
        }
Exemple #4
0
        private void BtnAddProduct_Click(object sender, EventArgs e)
        {
            Product product = new Product();


            int count = product.ToProduct();


            product.Count = 10;

            product.AddCount(3);

            product.AddCount(3333333333333333333);


            if (product.IsBuy)
            {
                MessageBox.Show("به سبد خرید افزدوه شد");
            }
            else
            {
                MessageBox.Show("شما هیچ محصولی رو انتخاب نکرده اید");
            }



            product.productbuyer[0] = new ProductBuyer()
            {
                Title = "Sony"
            };

            product.productbuyer[1] = new ProductBuyer()
            {
                Title = "Samsung"
            };



            ProductBuyer result = product["Sony1"];

            MessageBox.Show(result.Title);
        }
        public ActionResult Post(ProductBuyerViewModel vm)
        {
            ProductBuyer pt = AutoMapper.Mapper.Map <ProductBuyerViewModel, ProductBuyer>(vm);

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

                    try
                    {
                        _unitOfWork.Save();
                    }

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

                    LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                    {
                        DocTypeId    = new DocumentTypeService(_unitOfWork).FindByName(MasterDocTypeConstants.ProductBuyer).DocumentTypeId,
                        DocId        = pt.ProductBuyerId,
                        ActivityType = (int)ActivityTypeContants.Added,
                    }));

                    return(RedirectToAction("Create", new { ProductId = pt.ProductId }).Success("Data saved successfully"));
                }
                else
                {
                    List <LogTypeViewModel> LogList = new List <LogTypeViewModel>();

                    ProductBuyer temp = _ProductBuyerService.Find(pt.ProductBuyerId);

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

                    temp.BuyerId             = pt.BuyerId;
                    temp.BuyerSku            = pt.BuyerSku;
                    temp.BuyerProductCode    = pt.BuyerProductCode;
                    temp.BuyerSpecification  = pt.BuyerSpecification;
                    temp.BuyerSpecification1 = pt.BuyerSpecification1;
                    temp.BuyerSpecification2 = pt.BuyerSpecification2;
                    temp.BuyerSpecification3 = pt.BuyerSpecification3;
                    temp.BuyerSpecification4 = pt.BuyerSpecification4;
                    temp.BuyerSpecification5 = pt.BuyerSpecification5;
                    temp.BuyerSpecification6 = pt.BuyerSpecification6;
                    temp.BuyerUpcCode        = pt.BuyerUpcCode;
                    temp.ModifiedDate        = DateTime.Now;
                    temp.ModifiedBy          = User.Identity.Name;
                    temp.ObjectState         = Model.ObjectState.Modified;
                    _ProductBuyerService.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);
                        return(View("Create", pt));
                    }

                    LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                    {
                        DocTypeId       = new DocumentTypeService(_unitOfWork).FindByName(MasterDocTypeConstants.ProductBuyer).DocumentTypeId,
                        DocId           = temp.ProductBuyerId,
                        ActivityType    = (int)ActivityTypeContants.Modified,
                        xEModifications = Modifications,
                    }));

                    return(RedirectToAction("Index", new { id = vm.ProductId }).Success("Data saved successfully"));
                }
            }
            return(View("Create", vm));
        }
        public ActionResult SaleOrderExcelImport(int id)
        {
            int    BuyerId  = 0;
            var    file     = Request.Files[0];
            string filePath = Request.MapPath(ConfigurationManager.AppSettings["ExcelFilePath"] + file.FileName);

            file.SaveAs(filePath);
            var excel = new ExcelQueryFactory();

            //excel.FileName =ConfigurationManager.AppSettings["ExcelFilePath"]; //  @"C:\Users\guru\Downloads\PO.xls"; //TODO: Rempve hardcode
            excel.FileName = filePath;
            var SaleOrderRecordList = from c in excel.Worksheet <SaleOrderExcel>()  select c;

            StringBuilder strSku           = new StringBuilder();
            StringBuilder strSaleToBuyer   = new StringBuilder();
            StringBuilder strBillToBuyer   = new StringBuilder();
            StringBuilder strCurrency      = new StringBuilder();
            StringBuilder strShipMethod    = new StringBuilder();
            StringBuilder strDeliveryTerms = new StringBuilder();
            StringBuilder strPriority      = new StringBuilder();
            StringBuilder strOrderNo       = new StringBuilder();

            foreach (var SaleOrderRecord in SaleOrderRecordList)
            {
                if (_SaleOrderHeaderService.FindByDocNo(SaleOrderRecord.OrderNumber) != null)
                {
                    if (!strOrderNo.ToString().Contains("" + SaleOrderRecord.OrderNumber))
                    {
                        strOrderNo.Append(" " + SaleOrderRecord.OrderNumber + ",");
                    }
                }


                if (_ProductService.Find(SaleOrderRecord.Product) == null)
                {
                    if (!strSku.ToString().Contains("" + SaleOrderRecord.Product))
                    {
                        strSku.Append(" " + SaleOrderRecord.Product + ",");
                    }
                }
                if (SaleOrderRecord.SaleToBuyer != null)
                {
                    if (_BuyerService.GetBuyerByName(SaleOrderRecord.SaleToBuyer) == null)
                    {
                        if (!strSaleToBuyer.ToString().Contains("" + SaleOrderRecord.SaleToBuyer))
                        {
                            strSaleToBuyer.Append(" " + SaleOrderRecord.SaleToBuyer + ",");
                        }
                    }
                }
                if (SaleOrderRecord.BillToBuyer != null)
                {
                    if (_BuyerService.GetBuyerByName(SaleOrderRecord.BillToBuyer) == null)
                    {
                        if (!strBillToBuyer.ToString().Contains("" + SaleOrderRecord.BillToBuyer))
                        {
                            strBillToBuyer.Append(" " + SaleOrderRecord.BillToBuyer + ",");
                        }
                    }
                }
                if (SaleOrderRecord.Currency != null)
                {
                    if (_currencyService.GetCurrencyByName(SaleOrderRecord.Currency) == null)
                    {
                        if (!strCurrency.ToString().Contains("" + SaleOrderRecord.Currency))
                        {
                            strCurrency.Append(" " + SaleOrderRecord.Currency + ",");
                        }
                    }
                }
                if (SaleOrderRecord.ShipMethod != null)
                {
                    if (_ShipMethodService.GetShipMethodByName(SaleOrderRecord.ShipMethod) == null)
                    {
                        if (!strShipMethod.ToString().Contains("" + SaleOrderRecord.ShipMethod))
                        {
                            strShipMethod.Append(" " + SaleOrderRecord.ShipMethod + ",");
                        }
                    }
                }
                if (SaleOrderRecord.DeliveryTerms != null)
                {
                    if (_DeliveryTermsService.GetDeliveryTermsByName(SaleOrderRecord.DeliveryTerms) == null)
                    {
                        if (!strDeliveryTerms.ToString().Contains("" + SaleOrderRecord.DeliveryTerms))
                        {
                            strDeliveryTerms.Append(" " + SaleOrderRecord.DeliveryTerms + ",");
                        }
                    }
                }
                if (SaleOrderRecord.Priority != null)
                {
                    if (Enum.IsDefined(typeof(SaleOrderPriority), SaleOrderRecord.Priority) == false)
                    {
                        if (!strPriority.ToString().Contains("" + SaleOrderRecord.Priority))
                        {
                            strPriority.Append(" " + SaleOrderRecord.Priority + ",");
                        }
                    }
                }
            }
            if (!string.IsNullOrEmpty(strSku.ToString()) ||
                !string.IsNullOrEmpty(strOrderNo.ToString()) ||
                !string.IsNullOrEmpty(strSaleToBuyer.ToString()) ||
                !string.IsNullOrEmpty(strBillToBuyer.ToString()) ||
                !string.IsNullOrEmpty(strCurrency.ToString()) ||
                !string.IsNullOrEmpty(strShipMethod.ToString()) ||
                !string.IsNullOrEmpty(strDeliveryTerms.ToString()) ||
                !string.IsNullOrEmpty(strPriority.ToString()))
            {
                if (string.IsNullOrEmpty(strOrderNo.ToString()))
                {
                    ViewBag.orderno = null;
                }
                else
                {
                    ViewBag.orderno = strOrderNo;
                }
                if (string.IsNullOrEmpty(strSku.ToString()))
                {
                    ViewBag.product = null;
                }
                else
                {
                    ViewBag.product = strSku;
                }
                if (string.IsNullOrEmpty(strSaleToBuyer.ToString()))
                {
                    ViewBag.SaleToBuyer = null;
                }
                else
                {
                    ViewBag.SaleToBuyer = strSaleToBuyer;
                }
                if (string.IsNullOrEmpty(strBillToBuyer.ToString()))
                {
                    ViewBag.BillToBuyer = null;
                }
                else
                {
                    ViewBag.BillToBuyer = strBillToBuyer;
                }
                if (string.IsNullOrEmpty(strCurrency.ToString()))
                {
                    ViewBag.Currency = null;
                }
                else
                {
                    ViewBag.Currency = strCurrency;
                }
                if (string.IsNullOrEmpty(strShipMethod.ToString()))
                {
                    ViewBag.ShipMethod = null;
                }
                else
                {
                    ViewBag.ShipMethod = strShipMethod;
                }
                if (string.IsNullOrEmpty(strDeliveryTerms.ToString()))
                {
                    ViewBag.DeliveryTerms = null;
                }
                else
                {
                    ViewBag.DeliveryTerms = strDeliveryTerms;
                }
                if (string.IsNullOrEmpty(strPriority.ToString()))
                {
                    ViewBag.Priority = null;
                }
                else
                {
                    ViewBag.Priority = strPriority;
                }
                return(View());
            }
            else
            {
                string          previousRecord = null;
                int             count          = 0;
                SaleOrderHeader stemp          = new SaleOrderHeader();
                int             LinePk         = 0;
                foreach (var SaleOrderRecord in SaleOrderRecordList)
                {
                    if (count == 0 || SaleOrderRecord.OrderNumber != previousRecord)
                    {
                        //Object for SaleorderHeader Model to Save Order Num,Order Date, Ship Date and Supplier
                        SaleOrderHeader s = new SaleOrderHeader();

                        if (SaleOrderRecord.ShipAddress != null)
                        {
                            s.ShipAddress = SaleOrderRecord.ShipAddress;
                        }

                        s.DocDate       = SaleOrderRecord.OrderDate;
                        s.DocNo         = SaleOrderRecord.OrderNumber;
                        s.DueDate       = SaleOrderRecord.DueDate;
                        s.ActualDueDate = SaleOrderRecord.DueDate;
                        s.BuyerOrderNo  = SaleOrderRecord.BuyerOrderNo;
                        s.CreatedDate   = DateTime.Now;
                        s.ModifiedDate  = DateTime.Now;
                        s.CreatedBy     = User.Identity.Name;


                        s.ModifiedBy    = User.Identity.Name;
                        s.SaleToBuyerId = _BuyerService.GetBuyerByName(SaleOrderRecord.SaleToBuyer).PersonID;
                        if (SaleOrderRecord.BillToBuyer != null)
                        {
                            s.BillToBuyerId = _BuyerService.GetBuyerByName(SaleOrderRecord.BillToBuyer).PersonID;
                        }
                        else
                        {
                            s.BillToBuyerId = s.SaleToBuyerId;
                        }
                        BuyerId = s.SaleToBuyerId;

                        s.DivisionId = (int)System.Web.HttpContext.Current.Session["DivisionId"];
                        s.SiteId     = (int)System.Web.HttpContext.Current.Session["SiteId"];
                        SaleOrderSettings temp = new SaleOrderSettingsService(_unitOfWork).GetSaleOrderSettings(id, s.DivisionId, s.SiteId);

                        if (temp == null)
                        {
                            throw new Exception("Sale order settings is not configured");
                        }

                        if (SaleOrderRecord.Currency != null)
                        {
                            s.CurrencyId = _currencyService.GetCurrencyByName(SaleOrderRecord.Currency).ID;
                        }
                        else
                        {
                            s.CurrencyId = temp.CurrencyId;
                        }

                        if (SaleOrderRecord.ShipMethod == null)
                        {
                            s.ShipMethodId = temp.ShipMethodId;
                        }
                        else
                        {
                            s.ShipMethodId = _ShipMethodService.GetShipMethodByName(SaleOrderRecord.ShipMethod).ShipMethodId;
                        }

                        if (SaleOrderRecord.DeliveryTerms == null)
                        {
                            s.DeliveryTermsId = temp.DeliveryTermsId;
                        }
                        else
                        {
                            s.DeliveryTermsId = _DeliveryTermsService.GetDeliveryTermsByName(SaleOrderRecord.DeliveryTerms).DeliveryTermsId;
                        }

                        if (SaleOrderRecord.Priority == null)
                        {
                            s.Priority = temp.Priority;
                        }
                        else if (SaleOrderRecord.Priority == "Low")
                        {
                            s.Priority = (int)(SaleOrderPriority.Low);
                        }
                        else if (SaleOrderRecord.Priority == "High")
                        {
                            s.Priority = (int)(SaleOrderPriority.High);
                        }
                        else
                        {
                            s.Priority = (int)(SaleOrderPriority.Normal);
                        }

                        if (temp != null)
                        {
                            s.DocTypeId           = temp.DocTypeId;
                            s.UnitConversionForId = temp.UnitConversionForId;
                        }

                        _SaleOrderHeaderService.Create(s);
                        stemp = s;
                    }

                    //Object for SaleOrderLineDetail Model to Save Rate, Quantity, Product

                    Product       product = _ProductService.Find(SaleOrderRecord.Product);
                    SaleOrderLine sl      = new SaleOrderLine();
                    sl.SaleOrderHeaderId = stemp.SaleOrderHeaderId;
                    sl.Rate            = (decimal)SaleOrderRecord.Rate;
                    sl.Qty             = SaleOrderRecord.Quantity;
                    sl.ProductId       = product.ProductId;
                    sl.Specification   = product.ProductSpecification;
                    sl.DueDate         = SaleOrderRecord.DueDate;
                    sl.DealUnitId      = product.UnitId;
                    sl.CreatedDate     = DateTime.Now;
                    sl.ModifiedDate    = DateTime.Now;
                    sl.DealQty         = SaleOrderRecord.Quantity;
                    sl.CreatedBy       = User.Identity.Name;
                    sl.ModifiedBy      = User.Identity.Name;
                    sl.Amount          = sl.Rate * sl.Qty;
                    sl.SaleOrderLineId = LinePk++;

                    if (SaleOrderRecord.BuyerUpcCode != "" && SaleOrderRecord.BuyerUpcCode != null)
                    {
                        ProductBuyer productbuyer = new ProductBuyerService(_unitOfWork).Find(BuyerId, sl.ProductId);
                        if (productbuyer != null)
                        {
                            productbuyer.BuyerUpcCode = SaleOrderRecord.BuyerUpcCode;
                            new ProductBuyerService(_unitOfWork).Update(productbuyer);
                        }
                        else
                        {
                            ProductBuyer Temp = new ProductBuyer();
                            Temp.BuyerId      = BuyerId;
                            Temp.ProductId    = sl.ProductId;
                            Temp.BuyerUpcCode = SaleOrderRecord.BuyerUpcCode;
                            Temp.CreatedDate  = DateTime.Now;
                            Temp.ModifiedDate = DateTime.Now;
                            Temp.CreatedBy    = User.Identity.Name;
                            Temp.ModifiedBy   = User.Identity.Name;
                            Temp.ObjectState  = Model.ObjectState.Added;
                            new ProductBuyerService(_unitOfWork).Create(Temp);
                        }
                    }


                    _SaleOrderLineService.Create(sl);
                    new SaleOrderLineStatusService(_unitOfWork).CreateLineStatus(sl.SaleOrderLineId);

                    count++;
                    previousRecord = SaleOrderRecord.OrderNumber;

                    _unitOfWork.Save();
                }

                ViewBag.id = id;
                return(View("Sucess"));
            }
        }
 public void Update(ProductBuyer pt)
 {
     pt.ObjectState = ObjectState.Modified;
     _unitOfWork.Repository <ProductBuyer>().Update(pt);
 }
 public void Delete(ProductBuyer pt)
 {
     _unitOfWork.Repository <ProductBuyer>().Delete(pt);
 }
 public ProductBuyer Create(ProductBuyer pt)
 {
     pt.ObjectState = ObjectState.Added;
     _unitOfWork.Repository <ProductBuyer>().Insert(pt);
     return(pt);
 }
 public ProductBuyer Add(ProductBuyer pt)
 {
     _unitOfWork.Repository <ProductBuyer>().Insert(pt);
     return(pt);
 }
        public void Post(int SaleEnquiryLineId, string ProductName)
        {
            SaleEnquiryLine         Line         = new SaleEnquiryLineService(_unitOfWork).Find(SaleEnquiryLineId);
            SaleEnquiryLineExtended LineExtended = new SaleEnquiryLineExtendedService(_unitOfWork).Find(SaleEnquiryLineId);

            Product Product = new ProductService(_unitOfWork).Find(ProductName);

            if (Product != null)
            {
                Line.ProductId    = Product.ProductId;
                Line.ModifiedDate = DateTime.Now;
                Line.ModifiedBy   = User.Identity.Name;
                Line.ObjectState  = Model.ObjectState.Modified;
                new SaleEnquiryLineService(_unitOfWork).Update(Line);

                SaleEnquiryHeader Header = new SaleEnquiryHeaderService(_unitOfWork).Find(Line.SaleEnquiryHeaderId);

                ProductBuyer PB = new ProductBuyerService(_unitOfWork).Find((int)Header.SaleToBuyerId, Product.ProductId);
                if (PB == null)
                {
                    string BuyerSku = LineExtended.BuyerSpecification.Replace("-", "") + "-" + LineExtended.BuyerSpecification1 + "-" + LineExtended.BuyerSpecification2;

                    ProductBuyer ProdBuyer = new ProductBuyer();
                    ProdBuyer.BuyerId             = (int)Header.SaleToBuyerId;
                    ProdBuyer.ProductId           = Product.ProductId;
                    ProdBuyer.BuyerSku            = LineExtended.BuyerSku == null ? BuyerSku : LineExtended.BuyerSku;
                    ProdBuyer.BuyerUpcCode        = LineExtended.BuyerUpcCode;
                    ProdBuyer.BuyerSpecification  = LineExtended.BuyerSpecification;
                    ProdBuyer.BuyerSpecification1 = LineExtended.BuyerSpecification1;
                    ProdBuyer.BuyerSpecification2 = LineExtended.BuyerSpecification2;
                    ProdBuyer.BuyerSpecification3 = LineExtended.BuyerSpecification3;
                    ProdBuyer.CreatedDate         = DateTime.Now;
                    ProdBuyer.CreatedBy           = User.Identity.Name;
                    ProdBuyer.ModifiedDate        = DateTime.Now;
                    ProdBuyer.ModifiedBy          = User.Identity.Name;
                    ProdBuyer.ObjectState         = Model.ObjectState.Added;
                    new ProductBuyerService(_unitOfWork).Create(ProdBuyer);
                }

                SaleOrderHeader SaleOrderHeader = new SaleOrderHeaderService(_unitOfWork).Find_ByReferenceDocId(Header.DocTypeId, Header.SaleEnquiryHeaderId);
                if (SaleOrderHeader == null)
                {
                    CreateSaleOrder(Header.SaleEnquiryHeaderId);
                }
                else
                {
                    CreateSaleOrderLine(Line.SaleEnquiryLineId, SaleOrderHeader.SaleOrderHeaderId);
                }


                try
                {
                    _unitOfWork.Save();
                }

                catch (Exception ex)
                {
                    string message = _exception.HandleException(ex);
                }
            }
        }
        public ActionResult Post(SaleEnquiryLineViewModel vm)
        {
            if (ModelState.IsValid)
            {
                List <LogTypeViewModel> LogList = new List <LogTypeViewModel>();

                SaleEnquiryLine temp = new SaleEnquiryLineService(_unitOfWork).Find(vm.SaleEnquiryLineId);

                SaleEnquiryLine ExRec = Mapper.Map <SaleEnquiryLine>(temp);

                temp.ProductId    = vm.ProductId;
                temp.ModifiedDate = DateTime.Now;
                temp.ModifiedBy   = User.Identity.Name;
                temp.ObjectState  = Model.ObjectState.Modified;
                new SaleEnquiryLineService(_unitOfWork).Update(temp);

                ProductBuyer PB = new ProductBuyerService(_unitOfWork).Find((int)vm.SaleToBuyerId, (int)vm.ProductId);
                if (PB == null)
                {
                    string BuyerSku = vm.BuyerSpecification.Replace("-", "") + "-" + vm.BuyerSpecification1 + "-" + vm.BuyerSpecification2;

                    ProductBuyer ProdBuyer = new ProductBuyer();
                    ProdBuyer.BuyerId             = (int)vm.SaleToBuyerId;
                    ProdBuyer.ProductId           = (int)vm.ProductId;
                    ProdBuyer.BuyerSku            = vm.BuyerSku == null ? BuyerSku : vm.BuyerSku;
                    ProdBuyer.BuyerUpcCode        = vm.BuyerUpcCode;
                    ProdBuyer.BuyerSpecification  = vm.BuyerSpecification;
                    ProdBuyer.BuyerSpecification1 = vm.BuyerSpecification1;
                    ProdBuyer.BuyerSpecification2 = vm.BuyerSpecification2;
                    ProdBuyer.BuyerSpecification3 = vm.BuyerSpecification3;
                    ProdBuyer.CreatedDate         = DateTime.Now;
                    ProdBuyer.CreatedBy           = User.Identity.Name;
                    ProdBuyer.ModifiedDate        = DateTime.Now;
                    ProdBuyer.ModifiedBy          = User.Identity.Name;
                    ProdBuyer.ObjectState         = Model.ObjectState.Added;
                    new ProductBuyerService(_unitOfWork).Create(ProdBuyer);
                }

                SaleEnquiryHeader SaleEnquiryHeader = new SaleEnquiryHeaderService(_unitOfWork).Find(temp.SaleEnquiryHeaderId);
                SaleOrderHeader   SaleOrderHeader   = new SaleOrderHeaderService(_unitOfWork).Find_ByReferenceDocId(SaleEnquiryHeader.DocTypeId, SaleEnquiryHeader.SaleEnquiryHeaderId);
                if (SaleOrderHeader == null)
                {
                    CreateSaleOrder(temp.SaleEnquiryHeaderId);
                }
                else
                {
                    CreateSaleOrderLine(temp.SaleEnquiryLineId, SaleOrderHeader.SaleOrderHeaderId);
                }

                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);
                    return(View("Create", vm));
                }

                LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                {
                    DocTypeId       = new DocumentTypeService(_unitOfWork).FindByName(TransactionDoctypeConstants.SaleEnquiryProductMapping).DocumentTypeId,
                    DocId           = temp.SaleEnquiryLineId,
                    ActivityType    = (int)ActivityTypeContants.Modified,
                    xEModifications = Modifications,
                }));

                //return RedirectToAction("Index").Success("Data saved successfully");

                //var SaleEnquiryProductMapping = _SaleEnquiryLineService.GetSaleEnquiryLineListForIndex().OrderBy(m => m.SaleEnquiryLineId).OrderBy(m => m.SaleEnquiryLineId).FirstOrDefault();

                //if (SaleEnquiryProductMapping != null)
                //{
                //    return RedirectToAction("Edit", new { id = SaleEnquiryProductMapping.SaleEnquiryLineId }).Success("Data saved successfully");
                //}
                //else
                //{
                //    return RedirectToAction("Index").Success("Data saved successfully");
                //}

                int SaleEnquiryId = _SaleEnquiryLineService.NextId(vm.SaleEnquiryLineId);

                if (SaleEnquiryId > 0)
                {
                    return(RedirectToAction("Edit", new { id = SaleEnquiryId }).Success("Data saved successfully"));
                }
                else
                {
                    return(RedirectToAction("Index").Success("Data saved successfully"));
                }
            }
            return(View("Create", vm));
        }