示例#1
0
 public IEnumerable<SectionPrimitive> GetSections()
 {
     try
       {
     using (AtSolutionEntities context = new AtSolutionEntities())
     {
       return context.Sections.ToList().Select(x => x.GetPrimitive());
     }
       }
       catch (Exception e)
       {
     throw new FaultException<ExceptionDetail>(new ExceptionDetail(e), e.Message);
       }
 }
示例#2
0
 public SectionPrimitive GetSection(int id)
 {
     try
       {
     using (AtSolutionEntities context = new AtSolutionEntities())
     {
       var result = context.Sections.Where(x => x.Id == id).FirstOrDefault();
       if (result != null)
     return result.GetPrimitive();
       else
     return null;
     }
       }
       catch (Exception e)
       {
     throw new FaultException<ExceptionDetail>(new ExceptionDetail(e), e.Message);
       }
 }
示例#3
0
        public ArticlePrimitive CreateOrUpdateArticle(ArticlePrimitive articlePrimitive, SectionPrimitive sectionPrimitive)
        {
            try
              {
            using (AtSolutionEntities context = new AtSolutionEntities())
            {
              Article entity = articlePrimitive.GetEntity();

              Article existingEntity = context.Articles.Where(x => x.Id == articlePrimitive.Id).FirstOrDefault();

              //no record of this item in the DB, item being passed in has a PK
              if (existingEntity == null && entity.Id > 0)
              {
            throw new FaultException<ExceptionDetail>(new ExceptionDetail(new Exception("Błąd zapisu do bazy")),
                                                        "Obiekt nie istniał w bazie, a jego Id jest większe od 0.");
              }
              //Item has no PK value, must be new
              else if (entity.Id <= 0)
              {
            context.Articles.AddObject(entity);
              }
              //Item was retrieved, and the item passed has a valid ID, do an update
              else
              {
            context.Articles.ApplyCurrentValues(entity);
              }

              context.SaveChanges();
              return entity;
            }
              }
              catch (Exception e)
              {
            throw new FaultException<ExceptionDetail>(new ExceptionDetail(e), e.Message);
              }
        }