Example #1
0
        public bool UpdateValues(ItemsVM itemVm)
        {
            bool bChanged = false;
            if (ItemRef != itemVm.ItemRef)
            {
                ItemRef = itemVm.ItemRef;
                bChanged = true;
            }
            if (Name != itemVm.Name)
            {
                Name = itemVm.Name;
                bChanged = true;
            }

            if (Description != itemVm.Description)
            {
                Description = itemVm.Description;
                bChanged = true;
            }

            if (ListPrice != itemVm.ListPrice)
            {
                ListPrice = itemVm.ListPrice;
                bChanged = true;
            }

            if (SalePrice != itemVm.SalePrice)
            {
                SalePrice = itemVm.SalePrice;
                bChanged = true;
            }

            if (ArticleNo != itemVm.ArticleNo)
            {
                ArticleNo = itemVm.ArticleNo;
                bChanged = true;
            }

            if (Color != itemVm.Color)
            {
                Color = itemVm.Color;
                bChanged = true;
            }

            if (Category != itemVm.Category)
            {
                Category = itemVm.Category;
                bChanged = true;
            }

            if (Manufacturer != itemVm.Manufacturer)
            {
                Manufacturer = itemVm.Manufacturer;
                bChanged = true;
            }

            return bChanged;
        }
Example #2
0
 static public Items CreateFromViewModel(ItemsVM itemVm)
 {
     return new Items()
     {
         Id = itemVm.Id,
         ItemRef = itemVm.ItemRef,
         Name = itemVm.Name,
         ArticleNo = itemVm.ArticleNo,
         Category = itemVm.Category,
         Color = itemVm.Color,
         Description = itemVm.Description,
         ListPrice = itemVm.ListPrice,
         Manufacturer = itemVm.Manufacturer,
         SalePrice = itemVm.SalePrice
     };
 }
Example #3
0
 private ItemsVM AssignValues(XmlNode xItem)
 {
     int tmp;
     long lTmp; //If getting datetime, use long.TryParse(xCarElement.InnerText, out lTmp); and assign the value to FromUnixTime(lTmp);
     ItemsVM item = new ItemsVM();
     foreach (XmlNode xCarElement in xItem)
     {
         switch (xCarElement.Name)
         {
             case "id":
                 Int32.TryParse(xCarElement.InnerText.Replace(".", ""), out tmp);
                 item.ItemRef = tmp;
                 break;
             case "name":
                 item.Name = xCarElement.InnerText;
                 break;
             case "description":
                 item.Description = xCarElement.InnerText;
                 break;
             case "listprice":
                 Int32.TryParse(xCarElement.InnerText.Replace(".", ""), out tmp);
                 item.ListPrice = tmp;
                 break;
             case "saleprice":
                 Int32.TryParse(xCarElement.InnerText.Replace(".", ""), out tmp);
                 item.SalePrice = tmp;
                 break;
             case "articleno":
                 Int32.TryParse(xCarElement.InnerText.Replace(".", ""), out tmp);
                 item.ArticleNo = tmp;
                 break;
             case "color":
                 item.Color = xCarElement.InnerText;
                 break;
             case "category":
                 item.Category = xCarElement.InnerText;
                 break;
             case "manufacturer":
                 item.Manufacturer = xCarElement.InnerText;
                 break;
             default:
                 System.Diagnostics.Trace.WriteLine("Invalid child element: " + xCarElement.Name);
                 break;
         }
     }
     return item;
 }
Example #4
0
 public void OnRemoved(ItemsVM item)
 {
     _logger.Info("Removed - {0} {1} {2}", item.Name, item.Description, item.ArticleNo);
 }
Example #5
0
 public void OnUpdateError(ItemsVM item)
 {
     _logger.Error("Failed to Update - {0} {1} {2}", item.Name, item.Description, item.ArticleNo);
 }
Example #6
0
 public void OnUpdate(ItemsVM item)
 {
     _logger.Info("Update  - {0} {1} {2}", item.Name, item.Description, item.ArticleNo);
 }
Example #7
0
        public AddUpdateResult AddOrUpdate(ItemsVM itemVm, int itemId, DBCache cache)
        {
            try
            {
                if (itemId > 0)
                {
                    var existingItem = _Context.Items.Find(itemId);
                    if (existingItem != null)
                    {
                        bool bChanged = existingItem.UpdateValues(itemVm);
                        if (bChanged == false)
                            return AddUpdateResult.NoChange;

                        _Context.SaveChanges();
                        return AddUpdateResult.Updated;
                    }

                    return AddUpdateResult.Error;
                }

                var item = Items.CreateFromViewModel(itemVm);

                _Context.Items.Add(item);

                _Context.SaveChanges();
                itemVm.Id = item.Id;
                return AddUpdateResult.Added;
            }
            catch (DbEntityValidationException e)
            {
                Log(LogLevel.Error, GetExceptionMessage(e));
                throw;
            }
            catch (DbUpdateException e)
            {
                Log(LogLevel.Error, GetExceptionMessage(e));
                throw;
            }
        }
Example #8
0
        public void Add(ItemsVM itemVM)
        {
            try
            {
                var item = Items.CreateFromViewModel(itemVM);

                _Context.Items.Add(item);

                _Context.SaveChanges();
                itemVM.Id = item.Id;
            }
            catch (DbEntityValidationException e)
            {
                Log(LogLevel.Error, GetExceptionMessage(e));
                throw;
            }
            catch (DbUpdateException e)
            {
                Log(LogLevel.Error, GetExceptionMessage(e));

                throw;
            }
        }