Пример #1
0
        public Models.Product Create(Models.Product entity)
        {
            try
            {
                entity = ProductDataProccessor.ValidationAndProcess(entity);

                if (((new RestfulModels.Product()).Search(new Models.ProductSearchModel()
                {
                    VendorId = entity.VendorId, Title = entity.Title, Version = entity.Version
                })).Count() > 0)
                {
                    var e = new RestfulModels.ValidationException();
                    e.ValidationErrors.Add("已经存在");

                    throw e;
                }

                DbEntities.Products.AddObject(entity);
                DbEntities.SaveChanges();
                DbEntities.Refresh(System.Data.Objects.RefreshMode.StoreWins, entity);

                return(Read(entity.Id));
            }
            catch
            {
                throw;
            }
        }
Пример #2
0
        public Models.Product Update(int id, Models.Product entity)
        {
            try
            {
                entity    = ProductDataProccessor.ValidationAndProcess(entity);
                entity.Id = id;

                DbEntities.ApplyCurrentValues("Products", entity);
                DbEntities.SaveChanges();

                return(Read(entity.Id));
            }
            catch
            {
                throw;
            }
        }