///// <summary> ///// Method updates the details of existing cancellation details ///// </summary> ///// <param name="id"></param> ///// <param name="customer"></param> ///// <returns>return bool value</returns> public bool UpdateCancellation(int id, Cancellation cancellation) { try { using (AirlineDBEntities db = new AirlineDBEntities()) { db.Configuration.LazyLoadingEnabled = false; db.Entry(cancellation).State = EntityState.Modified; try { db.SaveChanges(); return(true); } catch (DbUpdateConcurrencyException) { if (!CancellationExists(id)) { return(false); } else { throw; } } } } catch (CancellationException) { throw new CancellationException("Id Doesnt Exists"); } }
public string post([FromBody] User_Registration stud) { string result = ""; try { var data = db.User_Registration.Where(x => x.EmailID == stud.EmailID).FirstOrDefault(); if (data == null) { return(result); } string OTP = GeneratePassword(); data.ActivationCode = Guid.NewGuid(); data.OTP = OTP; db.Entry(data).State = System.Data.EntityState.Modified; var res = db.SaveChanges(); if (res > 0) { ForgetPasswordEmailToUser(data.EmailID, data.ActivationCode.ToString(), data.OTP); result = "success"; return(result); } return(result); } catch (Exception ex) { throw ex; } }
///// <summary> ///// Method updates the details of existing cutomer's account details ///// </summary> ///// <param name="id"></param> ///// <param name="booking"></param> ///// <returns></returns> public bool UpdateBooking(int id, Booking booking) { using (AirlineDBEntities db = new AirlineDBEntities()) { db.Configuration.LazyLoadingEnabled = false; db.Entry(booking).State = EntityState.Modified; try { db.SaveChanges(); return(true); } catch (DbUpdateConcurrencyException) { if (!BookingExists(id)) { return(false); } else { throw; } } } }
public IHttpActionResult PutPassenger(long id, Passenger passenger) { //check for validation if (!ModelState.IsValid) { return(BadRequest(ModelState)); } //if the updated passenger id do not match with the given id it show BadRequest if (id != passenger.PassengerId) { return(BadRequest()); } //show the updated/edited details of passengers db.Entry(passenger).State = EntityState.Modified; try { db.SaveChanges(); } //Exception thrown by when it was expected that SaveChanges for //an passenger would result in a database update but in fact no rows in //the database were affected catch (DbUpdateConcurrencyException) { //if passenger id do not match(not existed) it return NOTFound if (!PassengerExists(id)) { return(NotFound()); } //otherwise throw the exception(DbUpdateConcurrencyException) else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }