示例#1
0
 public ActionResult <MomentStar> PostMomentStar(MomentStar momentStar)
 {
     _context.MomentStar.Add(momentStar);
     try{
         _context.SaveChanges();
     }
     catch (DbUpdateException) {
         if (MomentStarExists(momentStar))
         {
             return(Conflict());
         }
         else if (!MomentExists(momentStar.MomentId))
         {
             return(BadRequest());
         }
         else if (!FavouritePackageExists(momentStar.Account, momentStar.Name))
         {
             return(BadRequest());
         }
         else
         {
             throw;
         }
     }
     return(CreatedAtAction("GetMomentStar", new { id = momentStar.MomentId }, momentStar));
 }
示例#2
0
 private bool MomentStarExists(MomentStar momentStar)
 {
     return(_context.MomentStar.Any(e => (e.MomentId == momentStar.MomentId) &&
                                    (e.Account == momentStar.Account) && (e.Name == momentStar.Name)));
 }