public TravelEditModel(ConnextBusinessLayer.Bdd.TRAVEL objBdd) { Id = objBdd.ID_TRAVEL; Publication = new PublicationModel(objBdd.PUBLICATION); DepartureAgency = new AgencyLiteModel(objBdd.AGENCY); ArrivalAgency = new AgencyLiteModel(objBdd.AGENCY1); Capacity = objBdd.CAPACITY; DepartureTime = objBdd.DEPARTUREHOUR; ArrivalTime = objBdd.ARRIVALHOUR; }
public void add(TRAVEL travel) { try { var Context = new connext_dbEntities(); Context.TRAVELs.Add(travel); Context.SaveChanges(); } catch (Exception ex) { #if DEBUG throw new Exception("Impossible de modifier le covoiturage." + Environment.NewLine + ex.StackTrace); #else throw new Exception("Impossible de modifier le covoiturage."); #endif } }
// POST api/values public HttpResponseMessage Post(TravelEditModel model) { if (HttpContext.Current.Request.Headers["Authorization"] == null) { throw new HttpResponseException(HttpStatusCode.Unauthorized); } else { try { TRAVEL travelBdd = new TRAVEL(); travelBdd.ID_ARRIVALAGENCY = model.ArrivalAgency.Id; travelBdd.ID_DEPARTUREAGENCY = model.DepartureAgency.Id; travelBdd.ARRIVALHOUR = model.ArrivalTime; travelBdd.DEPARTUREHOUR = model.DepartureTime; travelBdd.CAPACITY = model.Capacity; PUBLICATION publicationBdd = new PUBLICATION(); string tokenString = HttpContext.Current.Request.Headers["Authorization"]; UserManager userManager = new UserManager(); publicationBdd.ID_USER = userManager.getUserFromSession(new Guid(tokenString)); publicationBdd.TITLE = model.Publication.Title; publicationBdd.DESCRIPTION = model.Publication.Description; publicationBdd.ID_GROUP = 1; publicationBdd.ID_CATEGORY = 1; publicationBdd.DATE_TIME_CREATION = DateTime.Now.AddHours(1); manager.add(travelBdd, publicationBdd); return new HttpResponseMessage() { Content = new JsonContent(new { Success = true, //error Message = "Success" //return exception }) }; } catch(Exception e) { return new HttpResponseMessage() { Content = new JsonContent(new { Success = false, //error Message = "Exception with token :" + HttpContext.Current.Request.Headers["Authorization"] + " Error :" + e.ToString() //return exception }) }; } } }