public ActionResult <Offer> CreateOffer([FromBody] Offer offer)
 {
     if (context.Offers.Where(x => x.UserId == offer.UserId && x.Subject == offer.Subject).Count() > 0)
     {
         Offer tempOffer = context.Offers.Where(x => x.UserId == offer.UserId && x.Subject == offer.Subject).First();
         tempOffer.TeacherId = offer.TeacherId;
         context.Offers.Update(tempOffer);
     }
     else
     {
         context.Offers.Add(new Offer()
         {
             UserId    = offer.UserId,
             Subject   = offer.Subject,
             TeacherId = offer.TeacherId
         });
     }
     try {
         context.SaveChanges();
     }
     catch (Exception ex) {
         return(BadRequest(ex));
     }
     return(offer);
 }
Example #2
0
 public ActionResult <User> CreateUser([FromBody] User user)
 {
     if (context.Users.Where(x => x.Id == user.Id).Count() > 0)
     {
         context.Users.Update(user);
     }
     else
     {
         context.Users.Add(user);
     }
     try {
         context.SaveChanges();
     }
     catch (Exception ex) {
         return(BadRequest(ex));
     }
     return(user);
 }