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

                if (((new RestfulModels.Vendor()).Search(new Models.VendorSearchModel()
                {
                    Title = entity.Title
                })).Count() > 0)
                {
                    var e = new RestfulModels.ValidationException();
                    e.ValidationErrors.Add("已经存在");

                    throw e;
                }

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

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

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

                return(entity);
            }
            catch
            {
                throw;
            }
        }