コード例 #1
0
ファイル: NotificationService.cs プロジェクト: GBoh/Shiftr
 public void CreateMessage(NotificationDTO m)
 {
     _repo.Add<Notification>(new Notification {
         Email = m.Email,
         Message = m.Message,
         IsRead = m.IsRead
     });
     _repo.SaveChanges();
 }
コード例 #2
0
ファイル: NotificationService.cs プロジェクト: GBoh/Shiftr
 //get a list of notifications
 public IList<NotificationDTO> ListMessage()
 {
     var messages = _repo.Query<Notification>().ToList();
     var messageDTO = new List<NotificationDTO>();
     foreach (var m in messages) {
         var mDTO = new NotificationDTO {
             Id = m.Id,
             Email = m.Email,
             Message = m.Message,
             IsRead = m.IsRead
         };
         messageDTO.Add(mDTO);
     }
     return messageDTO;
 }
コード例 #3
0
ファイル: NotificationController.cs プロジェクト: GBoh/Shiftr
        public HttpResponseMessage Post(NotificationDTO m)
        {
            if(ModelState.IsValid) {
                if(m.Id == 0) {
                    _service.CreateMessage(m);
                    return Request.CreateResponse(HttpStatusCode.OK, m);
                } else {
                    _service.UpdateMessage(m);
                    return Request.CreateResponse(HttpStatusCode.OK, m);
                }

            } else {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, this.ModelState);
            }
        }
コード例 #4
0
ファイル: NotificationService.cs プロジェクト: GBoh/Shiftr
 public void UpdateMessage(NotificationDTO m)
 {
     var message = _repo.Query<Notification>().FirstOrDefault(n => n.Id == m.Id);
     message.IsRead = m.IsRead;
     _repo.SaveChanges();
 }