Пример #1
0
        public void DeleteSalesOrder(SalesOrder salesOrder)
        {
            bool saveFailed = true;

            context.SalesOrders.Remove(salesOrder);

            while (saveFailed)
            {
                saveFailed = false;

                try
                {
                    context.SaveChanges();
                }
                catch (DbUpdateConcurrencyException ex)
                {
                    saveFailed = true;

                    // Reload with StoreWins
                    ex.Entries.Single().Reload();
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
Пример #2
0
        // needs to return value and display to user for user to choose ClientWins or StoreWins
        // Currently set to StoreWins
        public void SaveSalesOrder(SalesOrder salesOrder)
        {
            bool saveFailed = true;

            // if OrderID = 0 => Add new Order  else update modified Order
            if (salesOrder.OrderID == 0)
            {
                context.SalesOrders.Add(salesOrder);
            }

            //else
            //{
            //    context.SaveChanges();
            //}

            // Optimistic Concurrency implementation
            while (saveFailed)
            {
                saveFailed = false;

                try
                {
                    context.SaveChanges();
                }
                catch (DbUpdateConcurrencyException ex)
                {
                    saveFailed = true;

                    // Reload with StoreWins
                    ex.Entries.Single().Reload();
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
Пример #3
0
        public ActionResult SalesOrderCreate(SOCreateVM soCreateVM , string complete, string cancel, string clearall)
        {
            // get rid of SalesOrder in VM
            if (ModelState.IsValid)
            {
                if (!string.IsNullOrEmpty(complete))
                {
                    SalesOrder so = new SalesOrder();
                    so.OrderDetails = new List<SalesOrderDetail>();
                    so.OrderNo = soCreateVM.OrderNo;
                    so.DateOrdered = DateTime.Now;

                    foreach (OrderedProduct prod in soCreateVM.OrderedProducts)
                    {
                        // if returned product exist, then create new SalesOrderDetail and insert to table
                        //if (prod.ProductID != 0 && !String.IsNullOrEmpty(prod.ProductID.ToString()))
                        if(!String.IsNullOrEmpty(prod.Quantity.ToString()))
                        {
                            // TODO : Add GUID to SalesOrderDetail + SOVM + View
                            SalesOrderDetail soDetail = new SalesOrderDetail();
                            // soDetail.OrderID = soCreateVM.Order.OrderID ?? null;
                            soDetail.ProductID = prod.ProductID ?? null ;
                            soDetail.SKU = prod.SKU ?? "";
                            soDetail.ProductName = prod.Name ?? "";
                            soDetail.Quantity = prod.Quantity;
                            soDetail.Total = prod.SubTotal;

                            //if (!String.IsNullOrEmpty(prod.Price))
                            //{ soDetail.Price = Decimal.Parse(prod.Price.TrimStart('$')); }

                            soDetail.Price = prod.Price ?? null;

                            so.OrderDetails.Add(soDetail);
                        }
                    }

                    soRepo.SaveSalesOrder(so);

                    // return RedirectToAction("NewSalesOrder");
                    // return Redirect("/Main/SalesOrder");
                    return View("OrderCompleted");
                }
            }

            if (!string.IsNullOrEmpty(cancel))
            {
                return RedirectToAction("SalesOrderCreate");
                //return Redirect("/Main/SalesOrder");
            }
            //else
            //{
            //    return RedirectToAction("NewSalesOrder");
            //    // return Redirect("/Main/SalesOrder");

            //}

            return View(soCreateVM);
        }