Ejemplo n.º 1
0
        public Models.Aspect Create(Models.Aspect entity)
        {
            try
            {
                entity = AspectDataProccessor.ValidationAndProcess(entity);

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

                    throw e;
                }

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

                return(entity);
            }
            catch
            {
                throw;
            }
        }
Ejemplo n.º 2
0
        public Models.Aspect Update(int id, Models.Aspect entity)
        {
            try
            {
                entity    = AspectDataProccessor.ValidationAndProcess(entity);
                entity.Id = id;

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

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