public HttpResponseMessage Employee(int id, [FromBody] EmployeeModel employeeModel) { Trace.WriteLine("Invoking respository to update employee"); var updatedEmployee = TheModelFactory.Parse(employeeModel); if (updatedEmployee == null) { Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Could not read Employee details from body"); } var originalEmployee = TheRepository.GetEmployee(id); if (originalEmployee == null || originalEmployee.Id != id) { return(Request.CreateResponse(HttpStatusCode.NotModified, "Employee is not found")); } else { updatedEmployee.Id = id; } if (TheRepository.Update(originalEmployee, updatedEmployee) && TheRepository.SaveAll()) { return(Request.CreateResponse(HttpStatusCode.OK, TheModelFactory.Create(updatedEmployee))); } else { return(Request.CreateResponse(HttpStatusCode.NotModified)); } }
public HttpResponseMessage Put([FromBody] CalendarItemModel model) { try { var entity = TheModelFactory.Parse(model); if (entity == null) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "No Data to Post")); } else { var results = TheCalendarSupport.UpdateCalendarItem(model); if (results == null) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "No Data to Post")); } else { return(Request.CreateResponse(HttpStatusCode.Created, results)); } } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public HttpResponseMessage Post([FromBody] DiaryModel model) { try { Diary entity = TheModelFactory.Parse(model); if (entity == null) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Could not read diary body")); } //Check if diary exists for the current user. if (TheRepository.GetDiaries(_identityService.CurrentUser).Count(d => d.CurrentDate == model.CurrentDate.Date) > 0) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Duplicate diaries not allowed")); } entity.UserName = _identityService.CurrentUser; if (TheRepository.Insert(entity) && TheRepository.SaveAll()) { return(Request.CreateResponse(HttpStatusCode.Created, TheModelFactory.Create(entity))); } else { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Could Not Save to the Database")); } } catch (Exception e) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, e.ToString())); } }
public HttpResponseMessage Company(int id, [FromBody] CompanyModel companyModel) { Trace.WriteLine("Invoking respository to update a company"); var updatedCompany = TheModelFactory.Parse(companyModel); if (updatedCompany == null) { Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Could not read company details from body"); } var originalCompany = TheRepository.GetCompany(id); if (originalCompany == null || originalCompany.Id != id) { return(Request.CreateResponse(HttpStatusCode.NotModified, "Course is not found")); } else { updatedCompany.Id = id; } if (TheRepository.Update(originalCompany, updatedCompany) && TheRepository.SaveAll()) { return(Request.CreateResponse(HttpStatusCode.OK, TheModelFactory.Create(updatedCompany))); } else { return(Request.CreateResponse(HttpStatusCode.NotModified)); } }
public IHttpActionResult Put(int id, [FromBody] CourseModel courseModel) { try { var updatedCourse = TheModelFactory.Parse(courseModel); if (updatedCourse == null) { return(BadRequest("Could not read subject/tutor from body")); } var originalCourse = TheRepository.GetCourse(id, false); if (originalCourse == null || originalCourse.Id != id) { return(BadRequest("Course is not found")); } else { updatedCourse.Id = id; } if (TheRepository.Update(originalCourse, updatedCourse) && TheRepository.SaveAll()) { return(Ok <Course>(updatedCourse)); } else { return(BadRequest("error")); } } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public HttpResponseMessage Put(int id, [FromBody] ConductorModel conductorModel) { try { Conductor conductorActual = TheModelFactory.Parse(conductorModel); Conductor conductorOriginal = TheRepository.GetConductorById(id).First(); Conductor conductorExist = TheRepository.GetConductorByDNI(conductorActual.DNI).FirstOrDefault(); if (conductorOriginal == null) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "No se encontro conductor")); } if (conductorExist != null) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Ya existe un Conductor con ese DNI")); } if (TheRepository.Update(conductorOriginal, conductorActual) && TheRepository.SaveAll()) { return(Request.CreateResponse(HttpStatusCode.OK, TheModelFactory.Create(conductorOriginal))); } else { return(Request.CreateErrorResponse(HttpStatusCode.NotModified, "No se pudo salvar en la base de datos.")); } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public HttpResponseMessage Put(int id, [FromBody] CourseModel courseModel) { try { var updatedCourse = TheModelFactory.Parse(courseModel); if (updatedCourse == null) { Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Could not read subject/tutor from body"); } var originalCourse = TheRepository.getCourse(id, false); if (originalCourse.Id != id && originalCourse == null) { return(Request.CreateResponse(HttpStatusCode.NotModified, "Course is not found")); } else { updatedCourse.Id = id; } if (TheRepository.Update(originalCourse, updatedCourse) && TheRepository.SaveAll()) { return(Request.CreateResponse(HttpStatusCode.OK, TheModelFactory.Create(updatedCourse))); } else { return(Request.CreateResponse(HttpStatusCode.NotModified)); } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public HttpResponseMessage Post(DateTime diaryId, [FromBody] DiaryEntryModel model) { try { var entity = TheModelFactory.Parse(model); if (entity == null) { return(Request.CreateResponse(HttpStatusCode.BadRequest, "Could not read diary entry in body")); } var diary = TheRepository.GetDiary(_identityService.CurrentUser, diaryId); if (diary == null) { return(Request.CreateResponse(HttpStatusCode.NotFound)); } if (diary.Entries.Any(e => e.Measure.Id == entity.Measure.Id)) { return(Request.CreateResponse(HttpStatusCode.BadRequest, "Duplicate measures not allowed!")); } diary.Entries.Add(entity); TheRepository.SaveAll(); return(Request.CreateResponse(HttpStatusCode.Created, TheModelFactory.Create(entity))); } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public IHttpActionResult Patch(DateTime orderId, int id, [FromBody] OrderEntryModel model) { try { var entity = TheRepository.GetOrderEntry(_identityService.CurrentUser, orderId, id); if (entity == null) { return(NotFound()); } var parsedValue = TheModelFactory.Parse(model); if (parsedValue == null) { return(BadRequest()); } if (entity.Quantity != model.Quantity) { entity.Quantity = model.Quantity; if (TheRepository.SaveAll()) { return(Ok()); } } return(BadRequest()); } catch (Exception ex) { return(Content(HttpStatusCode.BadRequest, ex)); } }
public HttpResponseMessage Patch(DateTime diaryid, int id, [FromBody] DiaryEntryModel model) { try { var entity = TheRepository.GetDiaryEntry(_identityService.CurrentUser, diaryid, id); if (entity == null) { return(Request.CreateResponse(HttpStatusCode.NotFound)); } var parsedValue = TheModelFactory.Parse(model); if (parsedValue == null) { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } if (entity.Quantity != parsedValue.Quantity) { entity.Quantity = parsedValue.Quantity; if (TheRepository.SaveAll()) { return(Request.CreateResponse(HttpStatusCode.OK)); } } return(Request.CreateResponse(HttpStatusCode.BadRequest)); } catch (Exception e) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, e.ToString())); } }
public HttpResponseMessage Post([FromBody] DiaryModel model) { try { string username = _identityService.CurrentUser; if (TheRepository.GetDiaries(username).Count(d => d.CurrentDate == model.CurrentDate.Date) > 0) { return(Request.CreateErrorResponse(HttpStatusCode.Conflict, "A diary already exists for that date")); } Diary diary = TheModelFactory.Parse(model); diary.UserName = username; if (TheRepository.Insert(diary) && TheRepository.SaveAll()) { return(Request.CreateResponse(HttpStatusCode.Created, TheModelFactory.Create(diary))); } } catch { // TODO Add Logging } return(Request.CreateResponse(HttpStatusCode.BadRequest)); }
public HttpResponseMessage Post([FromBody] CourseModel courseModel) { try { var entity = TheModelFactory.Parse(courseModel); if (entity == null) { Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Could not read subject/tutor from body"); } if (TheRepository.Insert(entity) && TheRepository.SaveAll()) { return(Request.CreateResponse(HttpStatusCode.Created, TheModelFactory.Create(entity))); } else { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Could not save to the database.")); } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public HttpResponseMessage Post([FromBody] CalendarItemModel model) { try { var entity = TheModelFactory.Parse(model); if (entity == null) { Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Could not read Calendar Entry"); } //var calendarItem = TheCalendarSupport.GetCalendarItemById(calendarEntryModel.SiteUrl, calendarEntryModel.ListName, entity.Id); //if (calendarItem == null) Request.CreateResponse(HttpStatusCode.NotFound); var results = TheCalendarSupport.AddCalendarItem(entity); if (results == null) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "No Data to Post")); } else { return(Request.CreateResponse(HttpStatusCode.Created, results)); } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public HttpResponseMessage Post([FromBody] ConductorModel conductor) { try { Conductor conductorActual = TheModelFactory.Parse(conductor); if (conductorActual == null) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Conductor no encontrado")); } Conductor conductorExist = TheRepository.GetConductorByDNI(conductorActual.DNI).FirstOrDefault(); if (conductorExist != null) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Ya existe un Conductor con ese DNI")); } if (TheRepository.Insert(conductorActual)) { if (TheRepository.SaveAll()) { return(Request.CreateResponse(HttpStatusCode.Created, TheModelFactory.Create(conductorActual))); } return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "No se pudo salvar en la base de datos.")); } return(Request.CreateResponse(HttpStatusCode.BadRequest)); } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public HttpResponseMessage Put(int id, [FromBody] VehiculoModel vehiculo) { try { Vehiculo vehiculoActual = TheModelFactory.Parse(vehiculo); Vehiculo vehiculoOriginal = TheRepository.GetVehiculoById(id).FirstOrDefault(); Conductor conductorExist = TheRepository.GetConductorByDNI(vehiculo.DNI).FirstOrDefault(); if (vehiculoOriginal == null) { return(Request.CreateResponse(HttpStatusCode.NotModified, "No se encuentra el vehiculo regstrado")); } if (conductorExist == null) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "No está registrado el DNI como conductor.")); } else { vehiculoActual.Conductor = conductorExist; } vehiculoActual.Id = vehiculoOriginal.Id; IQueryable <Vehiculo> vehiculos = TheRepository.GetVehiculosByDNI(conductorExist.DNI); if (vehiculos.Count() > 10) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "El conductor ya esta resgistrado con el maximo de vehiculos.")); } if (TheRepository.Update(vehiculoOriginal, vehiculoActual) && TheRepository.SaveAll()) { return(Request.CreateResponse(HttpStatusCode.OK, TheModelFactory.Create(vehiculoActual))); } else { return(Request.CreateResponse(HttpStatusCode.NotModified)); } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public IHttpActionResult Put(int id, [FromBody] CourseModel courseModel) { try { var updatedCourse = TheModelFactory.Parse(courseModel); if (updatedCourse == null) { BadRequest("Could not read subject/tutor from body"); } var originalCourse = TheRepository.GetCourse(id); if (originalCourse == null || originalCourse.Id != id) { return(Content <string>(HttpStatusCode.NotModified, "Course is not found")); } else { updatedCourse.Id = id; } if (TheRepository.SaveAll())//TheRepository.Update(originalCourse, updatedCourse) && { return(Ok(TheModelFactory.Create(updatedCourse))); } else { return(Content <string>(HttpStatusCode.NotModified, "")); } } catch (DbEntityValidationException e) { foreach (var eve in e.EntityValidationErrors) { Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } return(BadRequest(e.Message)); } }
public HttpResponseMessage Employee([FromBody] EmployeeModel employeeModel) { Trace.WriteLine("Invoking respository to insert employee."); var entity = TheModelFactory.Parse(employeeModel); if (entity == null) { Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Could not read employee details from body"); } if (TheRepository.Insert(entity) && TheRepository.SaveAll()) { return(Request.CreateResponse(HttpStatusCode.Created, TheModelFactory.Create(entity))); } else { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Could not save to the database.")); } }
public HttpResponseMessage InsertCompany([FromBody] CompanyModel companyModel) { Trace.WriteLine("Invoking respository to insert a company"); var entity = TheModelFactory.Parse(companyModel); if (entity == null) { Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Could not read company details from body"); } if (TheRepository.Insert(entity) && TheRepository.SaveAll()) { return(Request.CreateResponse(HttpStatusCode.Created, TheModelFactory.Create(entity))); } else { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Request invalid")); } }
public HttpResponseMessage Post([FromBody] VehiculoModel vehiculo) { try { Vehiculo vehiculoActual = TheModelFactory.Parse(vehiculo); Vehiculo vehiculoExist = TheRepository.GetVehiculoByMatricula(vehiculo.Matricula); Conductor conductor = TheRepository.GetConductorByDNI(vehiculo.DNI).FirstOrDefault(); if (conductor == null || vehiculoExist != null) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "El vehiculo ya esta resgistrado o no está registrado el DNI como conductor.")); } else { vehiculoActual.Conductor = conductor; } IQueryable <Vehiculo> vehiculos = TheRepository.GetVehiculosByDNI(conductor.DNI); if (vehiculos.Count() > 10) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "El conductor ya esta resgistrado con el maximo de vehiculos.")); } if (TheRepository.Insert(vehiculoActual) && TheRepository.SaveAll()) { return(Request.CreateResponse(HttpStatusCode.Created, TheModelFactory.Create(vehiculoActual))); } else { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "No se pudo salvar en la base de datos.")); } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public HttpResponseMessage Post(DateTime diaryid, [FromBody] DiaryEntryModel model) { try { var entity = TheModelFactory.Parse(model); if (entity == null) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Could not read diary entry in body")); } var diary = TheRepository.GetDiary(_identityService.CurrentUser, diaryid); if (diary == null) { return(Request.CreateResponse(HttpStatusCode.NotFound)); } //make sure it is not a duplicate. //checks if the diary entry that is going to be added to the repository already exists by comparing the measureId of the entity to the existing measureIds in the diary. if (diary.Entries.Any(e => e.Measure.Id == entity.Measure.Id)) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Duplicate measures not allowed")); } diary.UserName = _identityService.CurrentUser; //saves the entry. diary.Entries.Add(entity); if (TheRepository.SaveAll()) { return(Request.CreateResponse(HttpStatusCode.Created, TheModelFactory.Create(entity))); } else { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Could Not Save to the Database")); } } catch (Exception e) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, e.ToString())); } }
public IHttpActionResult Post(DateTime orderId, [FromBody] OrderEntryModel model) { try { var entity = TheModelFactory.Parse(model); if (entity == null) { Content(HttpStatusCode.NotFound, "Could not read Order Entry in body"); } var order = TheRepository.GetOrder(_identityService.CurrentUser, orderId); if (order == null) { return(NotFound()); } //Make sure it is not duplicate if (order.Entries.Any(e => e.BookItem.Id == entity.BookItem.Id)) { return(Content(HttpStatusCode.BadRequest, "Duplicate Book not allowed")); } //save new entry order.Entries.Add(entity); if (TheRepository.SaveAll()) { return(Content(HttpStatusCode.Created, TheModelFactory.Create(entity))); } else { return(Content(HttpStatusCode.BadRequest, "Could not save to the database")); } } catch (Exception ex) { return(Content(HttpStatusCode.BadRequest, ex)); } }
public HttpResponseMessage Patch(DateTime date, int id, [FromBody] DiaryEntryModel model) { try { string username = _identityService.CurrentUser; DiaryEntry diaryEntry = TheRepository.GetDiaryEntry(username, date, id); if (diaryEntry == null) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Can't update a diary entry that does not exist")); } DiaryEntry newDiaryEntry = TheModelFactory.Parse(model); if (newDiaryEntry == null) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Could not read diary entry in body")); } // Nothing to change if (diaryEntry.Quantity == newDiaryEntry.Quantity) { return(Request.CreateResponse(HttpStatusCode.OK)); } diaryEntry.Quantity = newDiaryEntry.Quantity; if (TheRepository.SaveAll()) { return(Request.CreateResponse(HttpStatusCode.OK)); } else { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Could not save to the database")); } } catch (Exception exception) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, exception)); } }
public HttpResponseMessage Post(DateTime diaryId, [FromBody] DiaryEntryModel model) { try { var entity = TheModelFactory.Parse(model); if (entity == null) { Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Could not read diary entry in body."); } var diary = TheRepository.GetDiary(_identitySerivce.CurrentUser, diaryId); if (diary == null) { Request.CreateResponse(HttpStatusCode.NotFound); } // Make sure it's not duplicate if (diary.Entries.Any(e => e.Measure.Id == entity.Measure.Id)) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Duplicate Measure not allowed.")); } // Save the new entry diary.Entries.Add(entity); if (TheRepository.SaveAll()) { return(Request.CreateResponse(HttpStatusCode.Created, TheModelFactory.Create(entity))); } else { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Could not save to the database.")); } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public HttpResponseMessage Post(DateTime diaryID, [FromBody] DiaryEntryModel model) { try { var entity = TheModelFactory.Parse(model); if (entity == null) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Cannot read diary entry from Request Body")); } var diary = TheRepository.GetDiary(_identityService.CurrentUser, diaryID); //check if diary exists if (diary == null) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Cannot find diary")); } //check for duplicate entries if (diary.Entries.Any(e => e.Measure.Id == entity.Measure.Id)) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Cannot create diary entry as it already exists would you like to update entry")); } diary.Entries.Add(entity); if (TheRepository.SaveAll()) { return(Request.CreateResponse(HttpStatusCode.Created, TheModelFactory.Create(entity))); } else { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Cannot save to db")); } } catch (Exception e) { return(Request.CreateResponse(HttpStatusCode.BadRequest, "Could not create entity")); } }
public HttpResponseMessage Post(DateTime date, [FromBody] DiaryEntryModel model) { try { string username = _identityService.CurrentUser; DiaryEntry diaryEntry = TheModelFactory.Parse(model); if (diaryEntry == null) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Could not read diary entry in body")); } Diary diary = TheRepository.GetDiary(username, date); if (diary == null) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Diary not found")); } if (diary.Entries.Any(entry => entry.Measure.Id == diaryEntry.Measure.Id)) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Duplicate measure not allowed")); } diary.Entries.Add(diaryEntry); if (TheRepository.SaveAll()) { return(Request.CreateResponse(HttpStatusCode.Created, TheModelFactory.Create(diaryEntry))); } else { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Could not save to the database")); } } catch (Exception exception) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, exception)); } }
public HttpResponseMessage Post(DateTime diaryid, [FromBody] DiaryEntryModel model) { try { var entity = TheModelFactory.Parse(model); if (entity == null) { Request.CreateErrorResponse(HttpStatusCode.BadRequest, "cannot found entry"); } var diary = TheRepository.GetDiary(_identityService.CurrentUser, diaryid); if (diary == null) { Request.CreateResponse(HttpStatusCode.NotFound); } //check duplicate if (diary.Entries.Any(e => e.Measure.Id == entity.Measure.Id)) { return(Request.CreateResponse(HttpStatusCode.BadRequest, "duplicate")); } //save new entry diary.Entries.Add(entity); if (TheRepository.SaveAll()) { LogActivity.LogSend("post", Request); return(Request.CreateResponse(HttpStatusCode.OK, TheModelFactory.Create(entity))); } else { return(Request.CreateResponse(HttpStatusCode.BadRequest, "not added")); } } catch (Exception exception) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, exception)); } }
public HttpResponseMessage Patch(DateTime diaryId, int Id, [FromBody] DiaryEntryModel model) { try { var entity = TheRepository.GetDiaryEntry(_identityService.CurrentUser, diaryId, Id); if (entity == null) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Cannot find diary entry")); } var parsedValue = TheModelFactory.Parse(model); if (parsedValue == null) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Cannot parse model to diaryentry in model factory")); } if (entity.Quantity != parsedValue.Quantity) { entity.Quantity = parsedValue.Quantity; if (TheRepository.SaveAll()) { return(Request.CreateResponse(HttpStatusCode.OK)); } } //FALLBACK return(Request.CreateResponse(HttpStatusCode.BadRequest)); } catch (Exception e) { return(Request.CreateResponse(HttpStatusCode.BadRequest, "Could not find entity")); } }
public IHttpActionResult Post([FromBody] CourseModel courseModel) { try { var entity = TheModelFactory.Parse(courseModel); if (entity == null) { return(BadRequest("Could not read subject/tutor from body")); } if (TheRepository.Insert(entity) && TheRepository.SaveAll()) { return(Created <Course>(Request.RequestUri + entity.Id.ToString(), entity)); } else { return(BadRequest("Could not save to the database.")); } } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public IHttpActionResult Post([FromBody] CourseModel courseModel) { try { var entity = TheModelFactory.Parse(courseModel); if (entity == null) { return(BadRequest("Could not read subject/tutor from body")); } if (TheRepository.Insert(entity) && TheRepository.SaveAll()) { var newCourseModel = TheModelFactory.Create(entity); return(Created <CourseModel>(new Uri(newCourseModel.Url), newCourseModel)); } else { return(BadRequest("Could not save to database")); } } catch (Exception ex) { return(BadRequest(ex.Message)); } }