public async Task<IHttpActionResult> PutReservation(decimal id, Reservation reservation) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != reservation.ID) { return BadRequest(); } db.Entry(reservation).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ReservationExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }
public async Task<IHttpActionResult> PostReservationDTO(ReservationDTO res) { var paramName = new SqlParameter("@pv_name", res.Name); var paramGuest = new SqlParameter("@pn_guest", res.Guests); var paramEmail = new SqlParameter("@pv_email", res.Email); var paramPhone = new SqlParameter("@pv_phone", res.Phone); var paramComment = new SqlParameter("@pv_comment", res.Comment); var paramDate = new SqlParameter("@pv_date", res.Date); var paramTime = new SqlParameter("@pv_time", res.Time); var param_custId = new SqlParameter("@pv_cust_id", res.CustomerId); var id = new SqlParameter(); id.ParameterName = "@pn_output_id"; id.Direction = ParameterDirection.Output; id.SqlDbType = SqlDbType.Decimal; try { await db.Database.ExecuteSqlCommandAsync("Exec dbp_add_reservation @pv_name, @pn_guest, @pv_email,@pv_phone, @pv_comment,@pv_date,@pv_time, @pv_cust_id, @pn_output_id OUTPUT", paramName, paramGuest, paramEmail, paramPhone, paramComment, paramDate, paramTime, param_custId, id).ContinueWith((result) => { var spResult = result.Result; if (Convert.ToDecimal(id.Value) > 1) { res.ID = Convert.ToDecimal(id.Value); } }); await db.SaveChangesAsync(); } catch (AggregateException ex) { var excep = ex.Message; throw new ApplicationException(ex.Message); } catch (DbUpdateException) { if (ReservationExists(res.ID)) { return Conflict(); } else { throw; } } var reservation = new Reservation() { Name = res.Name, Phone = res.Phone, Comments = res.Comment, Email = res.Email, Guests = res.Guests, Time = res.Time, Date = res.Date, Active = "Y", InsertDateTime = DateTime.Now, InsertProcess = "Irfan", InsertUser = "******", ID = res.ID }; //var reservationlist = await GetReservationList(res.Phone, 5); return CreatedAtRoute("DefaultApi", new { controller = "Reservations", id = res.ID }, reservation); }
public async Task<IHttpActionResult> PostReservation(Reservation res) { //if (!ModelState.IsValid) //{ // return BadRequest(ModelState); //} var paramName = new SqlParameter("@pv_name", res.Name); var paramGuest = new SqlParameter("@pn_guest", res.Guests); var paramEmail = new SqlParameter("@pv_email", res.Email); var paramPhone = new SqlParameter("@pv_phone", res.Phone); var paramComment = new SqlParameter("@pv_comment", res.Comments); var paramDate = new SqlParameter("@pv_date", res.Date); var paramTime = new SqlParameter("@pv_time", res.Time); var id = new SqlParameter(); id.ParameterName = "@pn_output_id"; id.Direction = ParameterDirection.Output; id.SqlDbType = SqlDbType.Decimal; try { await db.Database.ExecuteSqlCommandAsync("Exec dbp_add_reservation @pv_name, @pn_guest, @pv_email,@pv_phone, @pv_comment,@pv_date,@pv_time, @pn_output_id OUTPUT", paramName, paramGuest, paramEmail, paramPhone, paramComment, paramDate, paramTime, id).ContinueWith((result)=> { var spResult = result.Result; if (Convert.ToDecimal(id.Value) > 1) { res.ID = Convert.ToDecimal(id.Value); } }); await db.SaveChangesAsync(); } catch(AggregateException ex) { var excep = ex.Message; } catch (DbUpdateException) { if (ReservationExists(res.ID)) { return Conflict(); } else { throw; } } return CreatedAtRoute("DefaultApi", new { id = res.ID }, res); }