public bool AddResponse(GuestResponse guestResponse) { //Set result to false bool result = false; //Check if email already used GuestResponse dbResponse = _dbContext.GuestResponses.FirstOrDefault(x => x.Email == guestResponse.Email); if (dbResponse != null) { //if guestResponse is the same the return wil be false if (dbResponse.WillAttend != guestResponse.WillAttend) { dbResponse.WillAttend = guestResponse.WillAttend; //Tell EF that state is modified _dbContext.Entry(dbResponse).State = EntityState.Modified; result = true; } } else { _dbContext.GuestResponses.Add(guestResponse); result = true; } _dbContext.SaveChanges(); return result; }
public ViewResult Rsvp(GuestResponse response, HttpPostedFileBase image = null) { if (ModelState.IsValid) { if (image != null) { response.ImageMimeType = image.ContentType; response.ImageData = new byte[image.ContentLength]; image.InputStream.Read(response.ImageData, 0, image.ContentLength); } _repository.AddResponse(response); return View("Thanks", response); } else { return View(); } }