public int DoUpadateOrInsertVendorProduct(VendorProduct model, bool isToUpdate, string submittedBy)
        {
            try
            {
                // NEED TO CREATE NEW DB CONTEXT SINCE THIS METHOD IS SHARED TO CONSOLE SERVICES
                using (var context = new EisInventoryContext())
                {
                    if (isToUpdate)
                    {
                        // get the existing vendor product
                        var product = context.vendorproducts.FirstOrDefault(x => x.EisSupplierSKU == model.EisSupplierSKU);
                        if (product == null)
                        {
                            return(0);
                        }

                        // set the new quantity for this vendor product
                        if (model.IsQuantitySet)
                        {
                            // get the number of order items which are Unshipped/Pending for this item
                            var pendingQtyOrders = context.orderproducts.Where(x => x.EisSupplierSKU == model.EisSupplierSKU)
                                                   .Join(context.orderitems,
                                                         op => op.OrderItemId,
                                                         oi => oi.OrderItemId,
                                                         (op, oi) => new { OrderProduct = op, OrderItem = oi })
                                                   .Join(context.orders.Where(x => x.OrderStatus == OrderStatus.Unshipped || x.OrderStatus == OrderStatus.Pending),
                                                         ooi => ooi.OrderItem.OrderId,
                                                         o => o.OrderId,
                                                         (ooi, o) => new { ooi.OrderProduct })
                                                   .Select(x => x.OrderProduct)
                                                   .DefaultIfEmpty <orderproduct>()
                                                   .Sum(x => (x == null ? 0 : x.Quantity));

                            // deduct the availability for this item with its pending orders
                            product.Quantity = model.Quantity - pendingQtyOrders;
                        }

                        if (model.Name != null)
                        {
                            product.Name = model.Name;
                        }
                        if (model.Description != null)
                        {
                            product.Description = model.Description;
                        }
                        if (model.IsSupplierPriceSet)
                        {
                            product.SupplierPrice = model.SupplierPrice;
                        }
                        if (model.IsMinPackSet)
                        {
                            product.MinPack = model.MinPack;
                        }
                        if (model.UPC != null)
                        {
                            product.UPC = model.UPC;
                        }
                        if (model.Category != null)
                        {
                            product.Category = model.Category;
                        }
                        if (model.Weight != null)
                        {
                            product.Weight = model.Weight;
                        }
                        if (model.WeightUnit != null)
                        {
                            product.WeightUnit = model.WeightUnit;
                        }
                        if (model.Shipping != null)
                        {
                            product.Shipping = model.Shipping;
                        }
                        if (model.VendorMOQ != null)
                        {
                            product.VendorMOQ = model.VendorMOQ;
                        }
                        if (model.VendorMOQType != null)
                        {
                            product.VendorMOQType = model.VendorMOQType;
                        }
                        if (model.IsAutoLinkToEisSKUSet)
                        {
                            product.IsAutoLinkToEisSKU = model.IsAutoLinkToEisSKU;
                        }

                        product.Modified   = DateTime.UtcNow;
                        product.ModifiedBy = submittedBy;
                        context.SaveChanges();

                        // let's set some properties; assuming that only EisSupplierSKU is supplied
                        // these data will be used when creating new EisSKU
                        model.Name             = product.Name;
                        model.Description      = product.Description;
                        model.ShortDescription = product.ShortDescription;
                        model.Category         = product.Category;
                        model.UPC         = product.UPC;
                        model.SubmittedBy = submittedBy;
                    }
                    else
                    {
                        var product = new vendorproduct();
                        CopyObject.CopyFields(model, product);
                        product.Created   = DateTime.UtcNow;
                        product.CreatedBy = submittedBy;

                        // add it to the context and save
                        context.vendorproducts.Add(product);
                        context.SaveChanges();
                    }
                    UpdateVendorProductImages(model.Images, model.EisSupplierSKU);
                }
                return(1);
            }
            catch (DbEntityValidationException ex)
            {
                var errorMsg = EisHelper.ParseDbEntityValidationException(ex);
                _logger.LogError(LogEntryType.VendorProductFileUploadWorker, errorMsg, ex.StackTrace);
                return(0);
            }
            catch (Exception ex)
            {
                _logger.LogError(LogEntryType.VendorProductFileUploadWorker,
                                 string.Format("Error in updating vendor product details -> SupplierSKU: {0} VendorId: {1}. <br/>Error message: {2}",
                                               model.SupplierSKU, model.VendorId, EisHelper.GetExceptionMessage(ex)),
                                 ex.StackTrace);
                return(0);
            }
        }
Exemple #2
0
        //public void ShowProgress(TableObject table)
        //{
        //	var Row = table.Row;
        //	//table.ShowProgress();

        //	//DataGridViewRow row = e.UserState as DataGridViewRow;

        //	//if (row != null)
        //	//{
        //	//   // this.dataGridView1.FirstDisplayedScrollingRowIndex = row.Index;
        //	//	//this.dataGridView1.Refresh();
        //	//	this.dataGridView1.CurrentCell = row.Cells[3];
        //	//	this.dataGridView1.UpdateCellValue(2, row.Index);
        //	//}
        //	if (Row != null)
        //	{
        //		//int i = (int) Math.Round((decimal) this.Copied / this.Count, 0) * 100;
        //		//Row.Cells[4].Value = e.ProgressPercentage;
        //		Row.Cells[4].Value = table.Percentage;
        //		var parent = Row.DataGridView;
        //		parent.CurrentCell = Row.Cells[3];
        //		parent.UpdateCellValue(2, Row.Index);
        //	}
        //}


        public async void CopyTablesAsync(CopyObject settings)
        {
            CopyManager manager = new CopyManager(settings);

            //manager.OnRowsCopied +=manager_OnRowsCopied;

            try
            {
                if (this.cbxDeleteRows.Checked)
                {
                    await Task.Run(() => manager.PreCopy());
                }
            }
            catch (Exception er)
            {
                MessageBox.Show(er.Message, "Pre SQL Error");
                return;
            }

            foreach (DataGridViewRow row in this.dataGridView1.Rows)
            {
                TableObject obj = (TableObject)row.DataBoundItem;

                // prepare
                obj.Row = row;
                //obj.Worker = worker;
                //worker.ReportProgress(0, obj);

                //if (worker.CancellationPending)
                //{
                //	break;
                //}
                try
                {
                    if (obj.Selected)
                    {
                        await Task.Run(() => manager.Copy(obj));

                        //manager.Copy(obj);
                        //obj.Status = "Success";
                        obj.CopyStatus = CopyStatusEnum.Success;
                        //this.ShowProgress(obj);

                        //worker.ReportProgress(0, row);
                        //worker.ReportProgress(100, obj);
                        //obj.ShowProgress();
                    }
                    else
                    {
                        obj.CopyStatus = CopyStatusEnum.Skipped;
                    }
                    obj.ShowProgress();
                }
                catch (Exception er)
                {
                    obj.CopyStatus = CopyStatusEnum.Error;
                    //obj.Status = er.Message;
                    obj.Message = er.Message;
                    //this.ShowProgress(obj);
                    obj.ShowProgress();
                    //worker.ReportProgress(0, er);
                    //worker.ReportProgress(0, row);
                    //worker.ReportProgress(0, obj);
                    //obj.ShowProgress();
                }
                finally
                {
                }
            }

            //foreach (TableObject obj in settings.Tables)
            //{
            //    if (worker.CancellationPending)
            //    {
            //        break;
            //    }
            //    try
            //    {
            //        if (obj.Selected)
            //        {
            //            manager.Copy(obj.Name);
            //            obj.Status = "Success";
            //            worker.ReportProgress(0);
            //        }
            //    }
            //    catch (Exception er)
            //    {
            //        obj.Status = er.Message;
            //        worker.ReportProgress(0, er);
            //    }
            //    finally
            //    {
            //    }
            //}

            try
            {
                if (this.cbxDeleteRows.Checked)
                {
                    await Task.Run(() => manager.PostCopy());

                    //manager.PostCopy();
                }
            }
            catch (Exception er)
            {
                MessageBox.Show(er.Message, "Post SQL Error");
                return;
            }
        }
Exemple #3
0
        // Background Version
        public void CopyTables(object sender, DoWorkEventArgs e)
        {
            //CopyObject settings = this.Settings;

            CopyObject settings = e.Argument as CopyObject;

            CopyManager manager = new CopyManager(settings);

            BackgroundWorker worker = (BackgroundWorker)sender;

            //manager.OnRowsCopied +=manager_OnRowsCopied;


            //ProgressChanged
            //worker.ReportProgress()

            try
            {
                if (this.cbxDeleteRows.Checked)
                {
                    manager.PreCopy();
                }
            }
            catch (Exception er)
            {
                MessageBox.Show(er.Message, "Pre SQL Error");
                return;
            }

            foreach (DataGridViewRow row in this.dataGridView1.Rows)
            {
                TableObject obj = (TableObject)row.DataBoundItem;

                // prepare
                obj.Row    = row;
                obj.Worker = worker;
                //worker.ReportProgress(0, obj);

                if (worker.CancellationPending)
                {
                    break;
                }
                try
                {
                    if (obj.Selected)
                    {
                        manager.Copy(obj);
                        //obj.Status = "Success";
                        obj.CopyStatus = CopyStatusEnum.Success;
                        //worker.ReportProgress(0, row);
                        worker.ReportProgress(100, obj);
                        //obj.ShowProgress();
                    }
                }
                catch (Exception er)
                {
                    obj.CopyStatus = CopyStatusEnum.Error;
                    obj.Message    = er.Message;
                    //obj.Status = er.Message;
                    //worker.ReportProgress(0, er);
                    //worker.ReportProgress(0, row);
                    worker.ReportProgress(0, obj);
                    //obj.ShowProgress();
                }
                finally
                {
                }
            }

            //foreach (TableObject obj in settings.Tables)
            //{
            //    if (worker.CancellationPending)
            //    {
            //        break;
            //    }
            //    try
            //    {
            //        if (obj.Selected)
            //        {
            //            manager.Copy(obj.Name);
            //            obj.Status = "Success";
            //            worker.ReportProgress(0);
            //        }
            //    }
            //    catch (Exception er)
            //    {
            //        obj.Status = er.Message;
            //        worker.ReportProgress(0, er);
            //    }
            //    finally
            //    {
            //    }
            //}

            try
            {
                if (this.cbxDeleteRows.Checked)
                {
                    manager.PostCopy();
                }
            }
            catch (Exception er)
            {
                MessageBox.Show(er.Message, "Post SQL Error");
                return;
            }
        }
Exemple #4
0
        public void CopySeveralObjects_interrelated()
        {
            // Test Setup
            var source = new List <ICmObject>();            // IEnumerable collection to feed to CopyObject

            var entry = Cache.ServiceLocator.GetInstance <ILexEntryFactory>().Create();

            source.Add(entry);

            var sense = Cache.ServiceLocator.GetInstance <ILexSenseFactory>().Create();

            entry.SensesOS.Add(sense);

            var msa = Cache.ServiceLocator.GetInstance <IMoStemMsaFactory>().Create();

            entry.MorphoSyntaxAnalysesOC.Add(msa);
            sense.MorphoSyntaxAnalysisRA = msa;

            var statusList = Cache.LanguageProject.StatusOA;

            if (statusList == null)
            {
                statusList = Cache.ServiceLocator.GetInstance <ICmPossibilityListFactory>().Create();
                Cache.LanguageProject.StatusOA = statusList;
            }
            if (statusList.PossibilitiesOS.Count == 0)
            {
                var status = Cache.ServiceLocator.GetInstance <ICmPossibilityFactory>().Create();
                statusList.PossibilitiesOS.Add(status);
            }
            sense.StatusRA = statusList.PossibilitiesOS[0];

            // SUT
            var copyColl = CopyObject <ICmObject> .CloneFdoObjects(source,
                                                                   CopyObject <ICmObject> .kAddToSourceOwner);

            var newList = new List <ICmObject>();

            foreach (ICmObject obj in copyColl)
            {
                newList.Add(obj);
            }

            // Verify results
            Assert.AreEqual(1, newList.Count, "Wrong number of copied objects.");
            // Verify new TextSegment
            var newEntry = newList[0] as ILexEntry;

            Assert.IsNotNull(newEntry, "Root entry failed to copy.");
            Assert.AreNotEqual(entry, newEntry, "Copy of entry should not be the same object.");

            Assert.AreEqual(1, newEntry.SensesOS.Count, "We should have same number of senses on the copy.");
            var newSense = newEntry.SensesOS[0];

            Assert.AreNotEqual(sense, newSense, "Copy of sense should not be the same object.");

            var newMsa = newEntry.MorphoSyntaxAnalysesOC.ToArray()[0];

            Assert.AreNotEqual(msa, newMsa, "Copy of Msa should not be the same object.");

            Assert.AreEqual(newMsa, newSense.MorphoSyntaxAnalysisRA, "The copy of the sense should point to the copy of the msa.");
            Assert.AreEqual(statusList.PossibilitiesOS[0], newSense.StatusRA, "The copy of the sense should point to the uncopied status.");
        }