Esempio n. 1
0
        public async Task <IHttpActionResult> PostNotification(eLublin.Web.Models.Api.CommitNotification commitNotification)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Notification notification = new Notification {
                czasDodania = DateTime.Now, tekst = commitNotification.tekst, url = commitNotification.url, tytul = commitNotification.tytul
            };

            db.Notifications.Add(notification);

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (NotificationExists(notification.id))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = notification.id }, notification));
        }
Esempio n. 2
0
        public async Task <IHttpActionResult> PutNotification(int id, eLublin.Web.Models.Api.CommitNotification commitNotification)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            //db.Entry(notification).State = EntityState.Modified;
            Notification notification = await db.Notifications.FirstAsync(x => x.id == id);

            notification.tekst = commitNotification.tekst;
            notification.url   = commitNotification.url;
            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!NotificationExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }