public ActionResult ResimYükle(HttpPostedFileBase file, int oid, string otel_oda) { if (file != null) { string pic = System.IO.Path.GetFileName(file.FileName); string path; if (otel_oda == "oda") { path = System.IO.Path.Combine( Server.MapPath("~/Content/assets/images/required/Fotolar/OdaFotolar"), pic); file.SaveAs(path); OdaFoto o = new OdaFoto(); o.OdaID = oid; o.Link = "/Content/assets/images/required/Fotolar/OdaFotolar/" + pic; m.OdaFoto.Add(o); m.SaveChanges(); } else { path = System.IO.Path.Combine( Server.MapPath("~/Content/assets/images/required/Fotolar/OtelFotolar"), pic); file.SaveAs(path); OtelFoto o = new OtelFoto(); o.OtelID = oid; o.Link = "/Content/assets/images/required/Fotolar/OtelFotolar/" + pic; m.OtelFoto.Add(o); m.SaveChanges(); } // file is uploaded // save the image path path to the database or you can send image // directly to database // in-case if you want to store byte[] ie. for DB using (MemoryStream ms = new MemoryStream()) { file.InputStream.CopyTo(ms); byte[] array = ms.GetBuffer(); } } if (otel_oda == "oda") { return(RedirectToAction("OdaGüncelleForm", "OtelYöneticisi", new { id = oid })); } else { return(RedirectToAction("Fotolar", "OtelYöneticisi")); } }
public ActionResult Arama(string arama, string şehir, int KişiSayısı, string giriş, string çıkış) { if (giriş == "" || çıkış == "") { Session["fail"] = true; return(RedirectToAction("../Home/Index")); } else { DateTime a = Convert.ToDateTime(giriş); giriş = a.ToString("yyyy-MM-dd"); DateTime b = Convert.ToDateTime(çıkış); çıkış = b.ToString("yyyy-MM-dd"); if (b <= a) { Session["fail"] = true; return(RedirectToAction("../Home/Index")); } } Session.Remove("fail"); ViewBag.giriş = giriş; ViewBag.çıkış = çıkış; ViewBag.kisiSayısı = KişiSayısı; ViewBag.Sehir = şehir; // var query1 = m.Database.SqlQuery<Oda>("select * from Oda as o where o.OtelID in(select ID from Otel where Şehir='"+şehir+"') and o.Kapasite>="+KişiSayısı+" and not exists (select * from Rezervasyon as r where r.OdaID=o.ID and ((r.GirişTarih>'"+giriş+"' and r.GirişTarih<'"+çıkış+"' ) or (r.ÇıkışTarih<'"+çıkış+"' and r.ÇıkışTarih>'"+giriş+"' ) or (r.GirişTarih<='"+giriş+"' )and r.ÇıkışTarih>='"+çıkış+"' ) )").ToList(); //Dictionary<int, List<Oda>> a = query1.GroupBy(c => c.OtelID).ToDictionary(t=>t.Key,t=>t.ToList()); //List<Oda> o = m.Oda.Where(x => x.Kapasite >= KişiSayısı).ToList(); //List<Otel> k = m.Otel.Where(x => x.Şehir == şehir).ToList(); List <Otel> query = new List <Otel>(); if (arama == "şehir" || arama == null) { string q = "select * from Otel where Otel.Şehir='" + şehir + "' and Otel.ID in (select OtelID from (select * from Oda as o where o.Kapasite>=" + KişiSayısı + " and not exists (select * from Rezervasyon as r where r.OdaID=o.ID and ((r.GirişTarih>'" + giriş + "' and r.GirişTarih<'" + çıkış + "' ) or (r.ÇıkışTarih<'" + çıkış + "' and r.ÇıkışTarih>'" + giriş + "' ) or (r.GirişTarih<='" + giriş + "' )and r.ÇıkışTarih>='" + çıkış + "' ) )) as o2)"; query = m.Database.SqlQuery <Otel>(q).ToList(); } else { string q2 = "select * from Otel where Otel.OtelAdı like '" + şehir + "%' and Otel.ID in (select OtelID from (select * from Oda as o where o.Kapasite>=" + KişiSayısı + " and not exists (select * from Rezervasyon as r where r.OdaID=o.ID and ((r.GirişTarih>'" + giriş + "' and r.GirişTarih<'" + çıkış + "' ) or (r.ÇıkışTarih<'" + çıkış + "' and r.ÇıkışTarih>'" + giriş + "' ) or (r.GirişTarih<='" + giriş + "' )and r.ÇıkışTarih>='" + çıkış + "' ) )) as o2)"; query = m.Database.SqlQuery <Otel>(q2).ToList(); // query.AddRange(query2); } var dict = new Dictionary <Otel, string>(); foreach (Otel o in query) { int id = o.ID; OtelFoto f = m.OtelFoto.Where(x => x.OtelID == id).FirstOrDefault(); if (f != null) { dict[o] = f.Link; } else { dict[o] = "/Content/assets/images/required/otelim_logo.png"; } } return(View(dict)); }