/// <summary> /// /// </summary> /// <param name="user"></param> /// <returns></returns> public HttpResponseMessage Post(User user) { HttpResponseMessage msg; using (ProjectAPIEntities _entites = new ProjectAPIEntities()) { try { var u = _entites.Users.FirstOrDefault(c => c.Username == user.Username); if (u == null) { _entites.Users.Add(user); _entites.SaveChanges(); msg = Request.CreateResponse(HttpStatusCode.Created, user); msg.Headers.Location = new Uri(Request.RequestUri + "/" + user.ID); } else { msg = Request.CreateErrorResponse(HttpStatusCode.Conflict, "Error! This UserName : "******" Is Not Available."); } return(msg); } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } } }
/// <summary> /// /// </summary> /// <param name="ID"></param> /// <param name="doctor"></param> /// <returns></returns> public HttpResponseMessage Put(int ID, Doctor doctor) { using (ProjectAPIEntities _entites = new ProjectAPIEntities()) { try { var myDoctor = _entites.Doctors.FirstOrDefault(d => d.Id == ID); if (myDoctor == null) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "User is not Found with this ID : " + ID)); } else { myDoctor.Name = doctor.Name; myDoctor.Title = doctor.Title; if (doctor.Image != null) { myDoctor.Image = doctor.Image; } _entites.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK, doctor)); } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } } }
/// <summary> /// /// </summary> /// <param name="course"></param> /// <returns></returns> public HttpResponseMessage Post(Course course) { HttpResponseMessage msg; using (ProjectAPIEntities _entites = new ProjectAPIEntities()) { try { //prevent Add course with an exist Cod var crs = _entites.Courses.FirstOrDefault(c => c.Code == course.Code); if (crs == null) { _entites.Courses.Add(course); _entites.SaveChanges(); msg = Request.CreateResponse(HttpStatusCode.Created, course); msg.Headers.Location = new Uri(Request.RequestUri + "/" + course.ID); } else { msg = Request.CreateErrorResponse(HttpStatusCode.Conflict, "Error! This Code : " + course.Code + " Is Not Available."); } return(msg); } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } } }
public IEnumerable <User> Get() { using (ProjectAPIEntities _entites = new ProjectAPIEntities()) { var users = _entites.Users.ToList(); return(users); } }
public IEnumerable <Doctor> Get() { using (ProjectAPIEntities _entites = new ProjectAPIEntities()) { // ده حل للايرور اللي طلع عيني ^_* _entites.Configuration.ProxyCreationEnabled = false; var doctors = _entites.Doctors.ToList(); return(doctors); } }
/// <summary> /// /// </summary> /// <param name="ID"></param> /// <returns></returns> public HttpResponseMessage Get(int ID) { using (ProjectAPIEntities _entites = new ProjectAPIEntities()) { var user = _entites.Users.FirstOrDefault(c => c.ID == ID && c.UserType != 1); if (user == null) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "User is not Found with this ID : " + ID)); } else { return(Request.CreateResponse(HttpStatusCode.OK, user)); } } }
/// <summary> /// /// </summary> /// <param name="ID"></param> /// <returns></returns> public HttpResponseMessage Delete(int ID) { using (ProjectAPIEntities _entites = new ProjectAPIEntities()) { var user = _entites.Users.FirstOrDefault(c => c.ID == ID); if (user == null) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "User is not Found with this ID : " + ID)); } else { _entites.Users.Remove(user); _entites.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK)); } } }
/// <summary> /// /// </summary> /// <param name="ID"></param> /// <returns></returns> public HttpResponseMessage Get(int ID) { using (ProjectAPIEntities _entites = new ProjectAPIEntities()) { // ده حل للايرور اللي طلع عيني ^_* _entites.Configuration.ProxyCreationEnabled = false; var doctor = _entites.Doctors.FirstOrDefault(d => d.Id == ID); if (doctor == null) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Doctor is not Found with this ID : " + ID)); } else { return(Request.CreateResponse(HttpStatusCode.OK, doctor)); } } }
/// <summary> /// /// </summary> /// <param name="ID"></param> /// <param name="myuser"></param> /// <returns></returns> public HttpResponseMessage Put(int ID, User myuser) { using (ProjectAPIEntities _entites = new ProjectAPIEntities()) { try { var u = _entites.Users.FirstOrDefault(c => c.Username == myuser.Username && c.ID != myuser.ID); if (u == null) { var user = _entites.Users.FirstOrDefault(c => c.ID == ID); if (user == null) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "User is not Found with this ID : " + ID)); } else { user.FirstName = myuser.FirstName; user.LastName = myuser.LastName; user.Email = myuser.Email; user.Gender = myuser.Gender; if (myuser.Image != null) { user.Image = myuser.Image; } user.Username = myuser.Username; user.Password = myuser.Password; _entites.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK, myuser)); } } else { return(Request.CreateErrorResponse(HttpStatusCode.Conflict, "Error! This UserName : "******" Is Not Available.")); } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } } }
/// <summary> /// /// </summary> /// <param name="doctor"></param> /// <returns></returns> public HttpResponseMessage Post(Doctor doctor) { HttpResponseMessage msg; using (ProjectAPIEntities _entites = new ProjectAPIEntities()) { try { _entites.Doctors.Add(doctor); _entites.SaveChanges(); msg = Request.CreateResponse(HttpStatusCode.Created, doctor); msg.Headers.Location = new Uri(Request.RequestUri + "/" + doctor.Id); return(msg); } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } } }
/// <summary> /// /// </summary> /// <param name="ID"></param> /// <param name="course"></param> /// <returns></returns> public HttpResponseMessage Put(int ID, Course course) { using (ProjectAPIEntities _entites = new ProjectAPIEntities()) { try { //prevent update course with an exist Code var crs = _entites.Courses.FirstOrDefault(c => c.Code == course.Code && c.ID != course.ID); if (crs == null) { var mycourse = _entites.Courses.FirstOrDefault(c => c.ID == ID); if (mycourse == null) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Course is not Found with this ID : " + ID)); } else { mycourse.Code = course.Code; mycourse.Describtion = course.Describtion; _entites.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK, course)); } } else { return(Request.CreateErrorResponse(HttpStatusCode.Conflict, "Error! This Code : " + course.Code + " Is Not Available.")); } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } } }