public HttpResponseMessage Put(tbl_Hospital hospital)
        {
            try
            {
                using (var db = new HastaneDBEntities())
                {
                    tbl_Hospital Hospital = db.tbl_Hospital.FirstOrDefault(x => x.HospitalID == hospital.HospitalID);

                    if (Hospital != null)
                    {
                        Hospital.HospitalName = hospital.HospitalName;
                        if (db.SaveChanges() > 0)
                        {
                            return(Request.CreateResponse(HttpStatusCode.OK, "Güncellendi"));
                        }
                        else
                        {
                            return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Güncelleme yapi1lamadi"));
                        }
                    }
                    else
                    {
                        return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Bulunamadı"));
                    }
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex));
            }
        }
示例#2
0
 public HttpResponseMessage Post(tbl_Hospital hospital)
 {
     try
     {
         using (var db = new HastaneDBEntities())
         {
             tbl_Hospital Hospital = db.tbl_Hospital.FirstOrDefault(x => x.HospitalName == hospital.HospitalName);
             if (db.tbl_Hospital.FirstOrDefault(x => x.HospitalName == hospital.HospitalName) != null)
             {
                 return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Bu hastane bulunmakta"));
             }
             else
             {
                 db.tbl_Hospital.Add(hospital);
                 db.SaveChanges();
                 return(Request.CreateResponse(HttpStatusCode.OK, hospital));
             }
         }
     }
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex));
     }
 }