コード例 #1
0
 public async Task <int> SaveComment(DtoComment comment)
 {
     try
     {
         using (var data = Context)
         {
             var p =
                 await
                     (from item in data.Comments where comment.Id == item.id select item).FirstOrDefaultAsync();
             // Updating
             if (p != null)
             {
                 p.comment = comment.Comment;
                 p.date    = comment.Date;
                 p.userId  = new UserLogic().GetUser(comment.Login).Id;
                 p.placeId = comment.PlaceId;
             }
             // Adding new
             else
             {
                 data.Comments.Add(CommentConverter.DtoToDataAccess(comment));
             }
             await data.SaveChangesAsync();
         }
         return(1);
     }
     catch (Exception)
     {
         return(0);
     }
 }
コード例 #2
0
 public static Comments DtoToDataAccess(DtoComment c)
 {
     return(new Comments
     {
         id = c.Id,
         date = c.Date,
         userId = new UserLogic().GetUser(c.Login).Id,
         placeId = c.PlaceId,
         comment = c.Comment
     });
 }