Beispiel #1
0
 public void Delete(Topic item)
 {
     var temp = db.Set<ForumDb.DbEntities.Topic>().First(n => n.Id == item.Id);
     if (temp != null)
     {
         db.Set<ForumDb.DbEntities.Topic>().Remove(EntityConverter.Convert(item));
         db.SaveChanges();
     }
 }
Beispiel #2
0
        public IHttpActionResult PostTopic(Topic topic)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            service.Add(topic);

            return CreatedAtRoute("DefaultApi", new { id = topic.Id }, topic);
        }
Beispiel #3
0
 public static ForumDb.DbEntities.Topic Convert(Topic entity)
 {
     return new ForumDb.DbEntities.Topic()
     {
         Id = entity.Id,
         InsertDate = entity.InsertDate,
         UpdateDate = entity.UpdateDate,
         Title = entity.Title,
         UserId = entity.UserId,
         Description = entity.Description
     };
 }
Beispiel #4
0
 public void Edit(Topic item)
 {
     db.Set<ForumDb.DbEntities.Topic>().Attach(EntityConverter.Convert(item));
     db.Entry<ForumDb.DbEntities.Topic>(EntityConverter.Convert(item)).State = EntityState.Modified;
     db.SaveChanges();
 }
Beispiel #5
0
 public void Add(Topic item)
 {
     db.Set<ForumDb.DbEntities.Topic>().Add(EntityConverter.Convert(item));
     db.SaveChanges();
 }
Beispiel #6
0
        // PUT api/Topic/5
        public IHttpActionResult PutTopic(int id, Topic topic)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != topic.Id)
            {
                return BadRequest();
            }

            service.Edit(topic);

            return StatusCode(HttpStatusCode.NoContent);
        }