예제 #1
0
        // PUT odata/Event(5)
        public async Task<IHttpActionResult> Put([FromODataUri] int key, Event @event)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (key != @event.Id)
            {
                return BadRequest();
            }

            db.Entry(@event).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!EventExists(key))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return Updated(@event);
        }
예제 #2
0
        // POST odata/Event
        public async Task<IHttpActionResult> Post(Event @event)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            db.Events.Add(@event);
            await db.SaveChangesAsync();

            return Created(@event);
        }
예제 #3
0
 private JsonEvent ToJsonEvent(Event e)
 {
     return new JsonEvent
     {
         Id = e.Id,
         Event = e.Text,
         Comments = e.Comments,
         Contact = e.Contact,
         Time = e.Time,
         SourceReliability = e.SourceReliability != null ? e.SourceReliability.Text : null,
         Topic = e.Topic,
         User = e.User != null ? e.User.Name : null
     };
 }