public bool Save(bool isSubmit, string userComment)
        {
            Dictionary<long, Dictionary<int, decimal>> summaryDict = new Dictionary<long, Dictionary<int, decimal>>(1);

            foreach (OrderProduct dbProduct in Products)
            {
                foreach (ProductMaterial dbMaterial in dbProduct.ProductMaterials)
                {
                    foreach (ProductMaterialItem item in dbMaterial.ProductMaterialItemsWrapper)
                    {
                        if (item.ProductMaterialItemID == 0)
                        {
                            dbMaterial.ProductMaterialItems.Add(item);
                        }
                    }
                }

                foreach (ProductCountryWiseBreakUp breakupItem in dbProduct.ProductBreakUpWrapper.ProductCountryWiseBreakUpWrapper)
                {
                    if (breakupItem.ProductCountryWiseBreakUpID == 0)
                    {
                        dbProduct.ProductBreakUp.ProductCountryWiseBreakUps.Add(breakupItem);
                    }
                    
                    if (!summaryDict.ContainsKey(breakupItem.ProductSize.ProductSizeID))
                    {
                        Dictionary<int, decimal> tmp = new Dictionary<int, decimal>(1);
                        summaryDict.Add(breakupItem.ProductSize.ProductSizeID, tmp);
                    }

                    if (!summaryDict[breakupItem.ProductSize.ProductSizeID].ContainsKey(breakupItem.Color.ColorID))
                    {
                        summaryDict[breakupItem.ProductSize.ProductSizeID].Add(breakupItem.Color.ColorID, breakupItem.NumberOfPiecesWrapper);
                    }
                    else
                    {
                        summaryDict[breakupItem.ProductSize.ProductSizeID][breakupItem.Color.ColorID] += breakupItem.NumberOfPiecesWrapper;
                    }
                }

                for (int i = 0; i < dbProduct.ProductBreakUpSummaries.Count; )
                {
                    dbProduct.ProductBreakUpSummaries.Remove(dbProduct.ProductBreakUpSummaries.ElementAt(i));
                }
                    
                foreach (KeyValuePair<long, Dictionary<int, decimal>> kvp in summaryDict)
                {
                    foreach (KeyValuePair<int, decimal> kvp2 in kvp.Value)
                    {
                        var productBreakUpSummaryInDB = (from record in dbProduct.ProductBreakUpSummaries
                                                            where record.ProductSizeID == kvp.Key && record.ColorID == kvp2.Value
                                                            select record).SingleOrDefault();

                        if (productBreakUpSummaryInDB == null)
                        {
                            ProductBreakUpSummary sumyItem = new ProductBreakUpSummary();
                            sumyItem.ProductID = dbProduct.ProductID;
                            sumyItem.ProductSizeID = kvp.Key;
                            sumyItem.ColorID = kvp2.Key;
                            sumyItem.NumberOfPieces = kvp2.Value;
                            dbProduct.ProductBreakUpSummaries.Add(sumyItem);
                        }
                        else
                        {
                            productBreakUpSummaryInDB.NumberOfPieces = kvp2.Value;
                        }
                    }
                }

                //Ugly code: But this is the only option for the time and money given
                dbProduct.RefreshExecutionTabProperties();
            }

            if (isSubmit)
            {
                m_Order.OrderStatusID = (short)OrderStatusEnum.SubMaterialsJobCompleted;
                AddDeleteButtonVisibility = Visibility.Hidden;
                foreach (OrderProduct dbProduct in Products)
                {
                    foreach (ProductMaterial dbMaterial in dbProduct.ProductMaterials)
                    {
                        foreach (ProductMaterialItem item in dbMaterial.ProductMaterialItemsWrapper)
                        {
                            item.OnPropertyChanged("IsEditable");
                        }
                    }
                }
            }

            #region History

            History historyItem = new History();
            historyItem.Date = DateTime.Now;
            historyItem.UserName = DBResources.Instance.CurrentUser.UserName;
            historyItem.Comment = userComment;

            if (isSubmit)
            {
                historyItem.OrderChanges = "Submitted in Material Details Page. Order Status Changed to " + m_Order.OrderStatu.DisplayLabel.ToUpper();
            }
            else
            {
                historyItem.OrderChanges = "Saved Changes in Material Details";
            }

            m_Order.Histories.Add(historyItem);

            #endregion

            return DBResources.Instance.UpdateOrderProducts();
        }
Beispiel #2
0
 public Order CreateNewOrder(Order newOrder, string userComment)
 {
     Order newSavedOrder = dbContext.Orders.Add(newOrder);
     History historyItem = new History();
     historyItem.Comment = userComment;
     historyItem.UserName = CurrentUser.UserName;
     historyItem.OrderChanges = "Created New Enquiry";
     historyItem.Date = DateTime.Now;
     newSavedOrder.Histories.Add(historyItem);
     Save();
     return newSavedOrder;
 }
        public bool Save(bool isSubmit, string userComment)
        {
            //Just to make sure
            Order.HasUserClickedSaveOrSubmit = true;

            if (!HasError)
            {
                if (isSubmit)
                {
                    if (Order.OrderStatusID == (short)OrderStatusEnum.EnquiryCreated || Order.OrderStatusID == (short)OrderStatusEnum.EnquiryRejected)
                        Order.OrderStatusID = (short)OrderStatusEnum.MaterialsAdded;
                    else if (Order.OrderStatusID == (short)OrderStatusEnum.MaterialsAdded)
                        Order.OrderStatusID = (short)OrderStatusEnum.MaterialsCostAdded;
                    //else if (Order.OrderStatusID == (short)OrderStatusEnum.MaterialsCostAdded)
                    //    Order.OrderStatusID = (short)OrderStatusEnum.MaterialsJobCompleted;
                }

                foreach (OrderProduct dbProduct in Products)
                {
                    foreach (ProductMaterial material in dbProduct.ProductMaterialsWrapper)
                    {
                        if (material.MaterialID == 0)
                        {
                            dbProduct.ProductMaterials.Add(material);
                        }
                    }
                    foreach (ProductExtraCost extraCost in dbProduct.ProductExtraCostWrapper)
                    {
                        if (extraCost.ProductID == 0)
                        {
                            dbProduct.ProductExtraCosts.Add(extraCost);
                        }
                    }
                }

                #region History

                History historyItem = new History();
                historyItem.Date = DateTime.Now;
                historyItem.UserName = DBResources.Instance.CurrentUser.UserName;
                historyItem.Comment = userComment;

                if (isSubmit)
                {
                    historyItem.OrderChanges = "Submitted in Materials Page. Order Stautus changed to " + Order.OrderStatu.DisplayLabel.ToUpper();
                }
                else
                {
                    historyItem.OrderChanges = "Saved changes in Materials";
                }

                Order.Histories.Add(historyItem);

                #endregion

                Order.LastModifiedDate = DBResources.Instance.GetServerTime();
                if (DBResources.Instance.UpdateOrderProducts())
                {
                    if (isSubmit)
                        ActionButtonsVisibility = Visibility.Hidden;
                    return true;
                }

                return false;
            }

            return false;
        }
 public virtual bool Save(string userComment, string executionType)
 {
     Order.LastModifiedDate = DBResources.Instance.GetServerTime();
     History historyItem = new History();
     historyItem.Date = DateTime.Now;
     historyItem.UserName = DBResources.Instance.CurrentUser.UserName;
     historyItem.Comment = userComment;
     historyItem.Order = Order;
     historyItem.OrderChanges = "has changed in " + executionType;
     Order.Histories.Add(historyItem);
     return DBResources.Instance.Save();
 }
        public bool UpdateOrderStatus(string userActionVerb, string userComment,OrderStatusEnum newStatus)
        {
            if (newStatus != OrderStatusEnum.None && Order != null)
            {
                Order.OrderStatusID = (short)newStatus;
                Order.LastModifiedDate = DBResources.Instance.GetServerTime();

                if (newStatus == OrderStatusEnum.EnquiryApproved)
                {
                    Order.OrderApprovedDate = DBResources.Instance.GetServerTime();
                }
                else if (newStatus == OrderStatusEnum.OrderConfirmed)
                {
                    Order.OrderConfirmedDate = DBResources.Instance.GetServerTime();
                }

                #region History

                History historyItem = new History();
                historyItem.Date = DateTime.Now;
                historyItem.UserName = DBResources.Instance.CurrentUser.UserName;
                historyItem.Comment = userComment;
                historyItem.OrderChanges = "has " + userActionVerb;

                Order.Histories.Add(historyItem);

                #endregion 

                bool isSuccessful = DBResources.Save();
                
                //Refresh UI 
                Order.OnPropertyChanged("TargetDatesGridVisibility");
                if (newStatus == OrderStatusEnum.OrderConfirmed)
                {
                    foreach(OrderReportCard reportCard in Order.OrderReportCards)
                    {
                        reportCard.OnPropertyChanged("IsReadOnly");
                    }
                }

                return isSuccessful;
            }
            return false;
        }