Example #1
0
        public void Save(ProductItem item)
        {
            var errors = item.GetValidationErrors();

            errors.ThrowIfHasErrors();

            var product = new tblProduct();

            if (item.Id != 0)
            {
                product = Db.Set <tblProduct>().Single(x => x.Id == item.Id);
            }
            else
            {
                product = Db.Set <tblProduct>().Create();
                Db.Set <tblProduct>().Add(product);
            }

            product.Descripton = item.Descripton;
            product.Name       = item.Name;
            product.YandexUrl  = item.YandexUrl;
            product.Specs      = item.Specs;
            product.CategoryId = item.CategoryId;

            Db.SaveChanges();

            item.Id = product.Id;
        }