public ActionResult AddEvent(zgloszenie ev) { using (szmalDBEvents events = new szmalDBEvents()) { if (!Logged()) { return(RedirectToAction("Index", "Login")); } try { if (Request.Files.Count > 0) { var binaryReader = new BinaryReader(Request.Files[0].InputStream); ev.image = binaryReader.ReadBytes((int)Request.Files[0].InputStream.Length); binaryReader.Dispose(); } ev.fk_login = (Session["UserID"].ToString()); ev.status = 0; events.zgloszenies.Add(ev); events.SaveChanges(); return(NewWindow(CreatePdf(ev))); } catch (Exception e) { return(View("~/Views/Home/Error.cshtml", e.Message)); } } }
string CreatePdf(zgloszenie ev) { string path = "~/Views/Raport/raport.cshtml"; string html = ""; string typ_zgloszenia; double dlugoscZgloszenie = 0, szerokoscZgloszenie = 0; NumberFormatInfo provider = new NumberFormatInfo(); provider.NumberDecimalSeparator = "."; zgloszenie objZgloszenie = null; szmalDBEvents db = new szmalDBEvents(); { objZgloszenie = db.zgloszenies.First(a => a.dlugosc.Equals(ev.dlugosc)); typ_zgloszenia = ev.typ_zgloszenia; try { dlugoscZgloszenie = Convert.ToDouble(ev.dlugosc, provider); szerokoscZgloszenie = Convert.ToDouble(ev.szerokosc, provider); } catch (Exception e) { Debug.Write(e.Message); } } IEnumerable <instytucja> obj = null; szmalDBOrganizations db1 = new szmalDBOrganizations(); { try { obj = (db1.instytucjas.Select(b => b).Where(c => c.działalnosc.Equals(typ_zgloszenia))). AsEnumerable().OrderBy(a => getDistance(dlugoscZgloszenie, szerokoscZgloszenie, Convert.ToDouble(a.dlugosc, provider), Convert.ToDouble(a.szerokosc, provider))); } catch (Exception e) { Debug.Write(e.Message); } } if (obj != null) { html = RenderRazorViewToString(path, new BigModelRaport() { instytucja = obj.First(), zgloszenie = objZgloszenie }); } //string sendto = obj.First().email; // Email(html, sendto); db.Dispose(); db1.Dispose(); return(html); }