public ActionResult Login(LoginViewModel model, string returnUrl) { if (!ModelState.IsValid) { return(View(model)); } Korisnik korisnik = new Korisnik(); using (var session = FluentNHibernateHelper.OpenSession()) { try { korisnik = ((List <Korisnik>)session.QueryOver <Korisnik>() .Where(k => k.Username == model.Email).List()).ElementAt(0); } catch (Exception e) { return(View()); } } if (korisnik.Lozinka == model.Password) { Session["LogIn"] = true; Session["User"] = korisnik; return(RedirectToAction("BucketItems", "Korisnik")); } else { return(View()); } }
public ActionResult ChangeBucketItem(int itemId) { BucketItem bucketItem = new BucketItem(); BuketListModelWithoutPicture buketListModel = new BuketListModelWithoutPicture(); using (var session = FluentNHibernateHelper.OpenSession()) { bucketItem = ((List <BucketItem>)session.QueryOver <BucketItem>() .Where(k => k.Id == itemId).List()).ElementAt(0); buketListModel.Id = bucketItem.Id; buketListModel.Ime = bucketItem.Ime; buketListModel.KategorijaId = bucketItem.Kategorija.Id.ToString(); buketListModel.Opis = bucketItem.Opis; buketListModel.Ostvareno = bucketItem.Ostvareno; List <Kategorija> kategorije = (List <Kategorija>)session .QueryOver <Kategorija>() .List(); foreach (var kategorija in kategorije) { SelectListItem selectListItem = new SelectListItem(); selectListItem.Text = kategorija.Naziv; selectListItem.Value = kategorija.Id.ToString(); buketListModel.kategorijaItems.Add(selectListItem); } } return(View(buketListModel)); }
public ActionResult Register(RegisterViewModel model) { if (ModelState.IsValid) { Korisnik korisnik = new Korisnik(); Image slika; using (var session = FluentNHibernateHelper.OpenSession()) { korisnik.Ime = model.Ime; korisnik.Prezime = model.Prezime; korisnik.Username = model.Email; korisnik.Moto = model.Moto; korisnik.Opis = model.Opis; korisnik.Lozinka = model.Password; if (model.Spol == "Male") { slika = Image.FromFile(Server.MapPath(@"~/Content/Images/boyDefault.PNG")); } else { slika = Image.FromFile(@"~/Content/Images/girlDefault.PNG"); } using (var ms = new MemoryStream()) { slika.Save(ms, System.Drawing.Imaging.ImageFormat.Png); korisnik.Slika = ms.ToArray(); } session.SaveOrUpdate(korisnik); Session["LogIn"] = true; Session["User"] = korisnik; } return(RedirectToAction("Index", "Home")); } return(View(model)); }
public ActionResult ChangeImage(ImageViewModel model) { if (!ModelState.IsValid) { // the user didn't upload any file => // render the same view again in order to display the error message return(RedirectToAction("Details", "Korisnik")); } Korisnik korisnik = (Korisnik)Session["User"]; MemoryStream target = new MemoryStream(); model.File.InputStream.CopyTo(target); byte[] data = target.ToArray(); korisnik.Slika = data; using (var session = FluentNHibernateHelper.OpenSession()) { session.Update(korisnik); session.Flush(); } return(RedirectToAction("Details", "Korisnik")); }
private void CreateTeendoDb(TeendoLista teendo) { using (var session = FluentNHibernateHelper.OpenSession()) using (var transaction = session.BeginTransaction()) { var ujTeendo = new Entities.TeendoLista() { Allapot = teendo.Allapot, Fontossag = teendo.Fontossag.ToString(), Hatarido = teendo.Hatarido, Letrehozas = teendo.Letrehozas, SzinKod = teendo.SzinkodMegadva ? teendo.SzinKod : null, }; foreach (var teendoListaElem in teendo.TeendoListaElemek) { var ujElem = new Entities.TeendoListaElem() { Szoveg = teendoListaElem.Szoveg, Teendo = ujTeendo }; ujTeendo.TeendoListaElemek.Add(ujElem); } session.Save(ujTeendo); transaction.Commit(); } }
public ActionResult Create(BuketListModel model) { try { BucketItem bucketItem = new BucketItem(); bucketItem.Ime = model.Ime; bucketItem.Ostvareno = model.Ostvareno; MemoryStream target = new MemoryStream(); model.Slika.InputStream.CopyTo(target); byte[] data = target.ToArray(); bucketItem.Slika = data; bucketItem.Opis = model.Opis; bucketItem.Korisnik = (Korisnik)Session["User"]; using (var session = FluentNHibernateHelper.OpenSession()) { List <Kategorija> kategorija = (List <Kategorija>)session.QueryOver <Kategorija>() .Where(k => k.Id == int.Parse(model.KategorijaId)).List(); bucketItem.Kategorija = kategorija[0]; session.SaveOrUpdate(bucketItem); } return(RedirectToAction("BucketItems", "Korisnik")); } catch { return(View()); } }
private void SaveTeendok(TeendokListaja lista) { /* * var toFile = _serializeService.Serialize(lista.Save()); * var result = _persisterService.Save(new Uri(_file), toFile); */ using (var session = FluentNHibernateHelper.OpenSession()) using (var transaction = session.BeginTransaction()) { foreach (var teendoBase in lista.Teendok) { var teendo = teendoBase as Teendo; if (teendo != null) { var ujTeendo = new Entities.Teendo() { Allapot = teendo.Allapot, Fontossag = teendo.Fontossag.ToString(), Hatarido = teendo.Hatarido, Letrehozas = teendo.Letrehozas, SzinKod = teendo.SzinkodMegadva ? teendo.SzinKod : null, Szoveg = teendo.Szoveg }; session.SaveOrUpdate(ujTeendo); } } transaction.Commit(); } }
private Entities.TeendoBase GetTeendoDb(int id) { using (var session = FluentNHibernateHelper.OpenSession()) { var teendo = session.Get <Entities.TeendoBase>(id); return(teendo); } }
public void DoCsvExport() { var session = FluentNHibernateHelper.OpenSession(); var records = session.Query <ScoredHandle>().ToList(); const string path = @"C:\Users\Nishant\Desktop\Dropbox\Ouzero\DatabaseExport.csv"; Utilities.WriteDatabaseExportFile(path, records); }
public IEnumerable <OperadoraDTO> Get() { using (ISession session = FluentNHibernateHelper.OpenSession()) { var operadoras = Mapper.Map <List <OperadoraDTO> >(session.Query <DataModel.Entities.Operadora>()); return(operadoras); } }
private void SaveTeendoDb(Entities.TeendoBase teendo) { using (var session = FluentNHibernateHelper.OpenSession()) using (var transaction = session.BeginTransaction()) { session.SaveOrUpdate(teendo); transaction.Commit(); } }
public void Insert(Product product) { //products.Add(product); using (ISession s = FluentNHibernateHelper.OpenSession()) { s.SaveOrUpdate(product); s.Flush(); } }
private static void RemoveTestCommitsFromDb() { var session = FluentNHibernateHelper.OpenSession(); using (session) { var rowsAffected = session.CreateQuery("delete from ScoredHandle where Username = '******'").ExecuteUpdate(); Console.WriteLine(@"Delete, affected rows: " + rowsAffected); } }
private void DeleteTeendoDb(int id) { var toroltTeendo = GetTeendoDb(id); using (var session = FluentNHibernateHelper.OpenSession()) using (var transaction = session.BeginTransaction()) { session.Delete(toroltTeendo); transaction.Commit(); } }
public ActionResult BucketItemsMobile() { var bucketItemsModel = new BucketItemsModel(); using (var session = FluentNHibernateHelper.OpenSession()) { List <BucketItem> bucketItems = (List <BucketItem>)session.QueryOver <BucketItem>().List(); return(Json(bucketItems)); } }
public ActionResult usernameSubmit(string newUsername) { Korisnik korisnik = (Korisnik)Session["User"]; korisnik.Username = newUsername; Session["User"] = korisnik; using (var session = FluentNHibernateHelper.OpenSession()) { session.Update(korisnik); session.Flush(); } return(RedirectToAction("Details")); }
public HttpResponseMessage GetContatos() { try { using (ISession session = FluentNHibernateHelper.OpenSession()) { var contatos = Mapper.Map <List <ContatoDTO> >(session.Query <Contato>()); return(Request.CreateResponse(HttpStatusCode.OK, contatos)); } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message)); } }
public ActionResult About() { Korisnik prviKorisnik; using (var session = FluentNHibernateHelper.OpenSession()) { List <Korisnik> korisnik = (List <Korisnik>)session.QueryOver <Korisnik>() .Where(k => k.Id == 4).List(); prviKorisnik = korisnik.ElementAt(0); BucketItem bucketItem = prviKorisnik.BucketItems[0]; } ViewBag.Message = "Your application username: " + prviKorisnik.Username; return(View()); }
public HttpResponseMessage Post([FromBody] KorisnikModel Korisnik) { if (ModelState.IsValid) { Korisnik korisnik = new Korisnik(); Image Slika; using (var session = FluentNHibernateHelper.OpenSession()) { korisnik.Ime = Korisnik.Ime; korisnik.Prezime = Korisnik.Prezime; korisnik.Username = Korisnik.Username; korisnik.Moto = Korisnik.Moto; korisnik.Opis = Korisnik.Opis; korisnik.Lozinka = Korisnik.Lozinka; if (Korisnik.Slika == null) { //Slika = Image.FromFile(@"~/Content/Images/boyDefault.png"); //using (var ms = new MemoryStream()) //{ // Slika.Save(ms, System.Drawing.Imaging.ImageFormat.Png); // korisnik.Slika = ms.ToArray(); //} } else { korisnik.Slika = Korisnik.Slika; } session.SaveOrUpdate(korisnik); } var novi = new KorisnikModel(); novi.Id = korisnik.Id; novi.Ime = korisnik.Ime; novi.Lozinka = korisnik.Lozinka; novi.Moto = korisnik.Moto; novi.Opis = korisnik.Opis; novi.Prezime = korisnik.Prezime; novi.Slika = korisnik.Slika; novi.Username = korisnik.Username; response = Request.CreateResponse(HttpStatusCode.OK, novi); return(response); } Korisnik prazan = new Korisnik(); response = Request.CreateResponse(HttpStatusCode.OK, prazan); return(response); }
private static void DoTestCommit(string name) { var session = FluentNHibernateHelper.OpenSession(); using (session) { using (var transaction = session.BeginTransaction()) { var scoredHandle = new ScoredHandle { Username = name, Name = "FluentName", Followers = 10, FavouriteRate = 2, Friends = 10, RetweetRate = 3, ImgUrl = "img", Score = 99, Website = "webby", Category = "Test", Location = "London", AlexaPagePerf = 0, AlexaBounce = 0, AlexaTraffic = 1000, Bio = "Bio", AlexaRank = 0 }; session.SaveOrUpdate(scoredHandle); transaction.Commit(); } } }
private void CreateTeendoDb(Teendo teendo) { using (var session = FluentNHibernateHelper.OpenSession()) using (var transaction = session.BeginTransaction()) { var ujTeendo = new Entities.Teendo() { Allapot = teendo.Allapot, Fontossag = teendo.Fontossag.ToString(), Hatarido = teendo.Hatarido, Letrehozas = teendo.Letrehozas, SzinKod = teendo.SzinkodMegadva ? teendo.SzinKod : null, Szoveg = teendo.Szoveg }; session.Save(ujTeendo); transaction.Commit(); } }
public ActionResult ChangeBucketItem(BuketListModelWithoutPicture bucketModel) { BucketItem bucketItem = new BucketItem(); using (var session = FluentNHibernateHelper.OpenSession()) { bucketItem = ((List <BucketItem>)session.QueryOver <BucketItem>() .Where(k => k.Id == bucketModel.Id).List()).ElementAt(0); bucketItem.Ime = bucketModel.Ime; bucketItem.Opis = bucketModel.Opis; bucketItem.Ostvareno = bucketModel.Ostvareno; List <Kategorija> kategorija = (List <Kategorija>)session.QueryOver <Kategorija>() .Where(k => k.Id == int.Parse(bucketModel.KategorijaId)).List(); bucketItem.Kategorija = kategorija[0]; session.Update(bucketItem); session.Flush(); } return(RedirectToAction("BucketItems")); }
// GET: Korisnik/Create public ActionResult Create() { BuketListModel bucketListModel = new BuketListModel(); using (var session = FluentNHibernateHelper.OpenSession()) { List <Kategorija> kategorije = (List <Kategorija>)session .QueryOver <Kategorija>() .List(); foreach (var kategorija in kategorije) { SelectListItem selectListItem = new SelectListItem(); selectListItem.Text = kategorija.Naziv; selectListItem.Value = kategorija.Id.ToString(); bucketListModel.kategorijaItems.Add(selectListItem); } } return(View(bucketListModel)); }
public HttpResponseMessage Create([FromBody] BucketItemModel model, int id) { try { BucketItem bucketItem = new BucketItem(); bucketItem.Ime = model.Ime; bucketItem.Ostvareno = false; if (model.Slika == null) { bucketItem.Slika = null; } else { bucketItem.Slika = model.Slika; } bucketItem.Opis = model.Opis; Korisnik kor = new Korisnik(); using (var session = FluentNHibernateHelper.OpenSession()) { kor = ((List <Korisnik>)session.QueryOver <Korisnik>() .Where(k => k.Id == id).List()).ElementAt(0); bucketItem.Korisnik = kor; List <Kategorija> kategorija = (List <Kategorija>)session.QueryOver <Kategorija>() .Where(k => k.Naziv == model.KategorijaNaziv).List(); bucketItem.Kategorija = kategorija[0]; session.SaveOrUpdate(bucketItem); } response = Get(id); return(response); } catch { response = Request.CreateResponse(HttpStatusCode.NotFound, "Ne"); return(response); } }
public HttpResponseMessage Get(string username, string password) { Korisnik korisnik = new Korisnik(); Korisnik prazan = new Korisnik(); using (var session = FluentNHibernateHelper.OpenSession()) { try { korisnik = ((List <Korisnik>)session.QueryOver <Korisnik>() .Where(k => k.Username == username).List()).ElementAt(0); } catch (Exception e) { response = Request.CreateResponse(HttpStatusCode.OK, prazan); return(response); } } if (korisnik.Lozinka == password) { var novi = new KorisnikModel(); novi.Id = korisnik.Id; novi.Ime = korisnik.Ime; novi.Lozinka = korisnik.Lozinka; novi.Moto = korisnik.Moto; novi.Opis = korisnik.Opis; novi.Prezime = korisnik.Prezime; novi.Slika = korisnik.Slika; novi.Username = korisnik.Username; response = Request.CreateResponse(HttpStatusCode.OK, novi); return(response); } else { response = Request.CreateResponse(HttpStatusCode.OK, prazan); return(response); } }
public HttpResponseMessage GetContato(int id) { try { using (ISession session = FluentNHibernateHelper.OpenSession()) { var contato = Mapper.Map <ContatoDTO>(session.Get <Contato>(id)); if (contato == null) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Contato não encontrado.")); } return(Request.CreateResponse(HttpStatusCode.OK, contato)); } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message)); } }
public ActionResult changeOstvareno(string ostvareno, int bucketItemId) { BucketItem bucketItem = new BucketItem(); using (var session = FluentNHibernateHelper.OpenSession()) { bucketItem = ((List <BucketItem>)session.QueryOver <BucketItem>() .Where(k => k.Id == bucketItemId).List()).ElementAt(0); if (ostvareno == "nijeOstvareno") { bucketItem.Ostvareno = false; } else { bucketItem.Ostvareno = true; } session.Update(bucketItem); session.Flush(); } return(RedirectToAction("BucketItems")); }
public string GetForm(decimal id) { ObjectForm form = new ObjectForm(); try { var session = FluentNHibernateHelper.OpenSession(); var lst = session.QueryOver <ObjectForm>() .Where(x => x.id == id) .List <ObjectForm>(); form = lst.FirstOrDefault(); jsForm jsform = new jsForm(form); JavaScriptSerializer s = new JavaScriptSerializer(); var str = s.Serialize(jsform); return(str); } catch (Exception ex) { throw new WebFaultException <string>(ex.Message, System.Net.HttpStatusCode.InternalServerError); } }
public HttpResponseMessage DeleteContatos(List <ContatoDTO> contatosExcluir) { using (ISession session = FluentNHibernateHelper.OpenSession()) { try { foreach (var item in contatosExcluir) { var contatoExcluir = Mapper.Map <Contato>(item); session.Delete(contatoExcluir); } session.Flush(); return(Request.CreateResponse(HttpStatusCode.OK, "Deletados com sucesso"));; } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message));; } } }
public string GetMenu() { MainMenuItem mmi = new MainMenuItem(); try { var session = FluentNHibernateHelper.OpenSession(); var lst = session.QueryOver <MainMenuItem>() .Where(x => x.idParent == null) .List <MainMenuItem>(); mmi = lst.FirstOrDefault(); JavaScriptSerializer s = new JavaScriptSerializer(); var str = s.Serialize(mmi); return(str); } catch (Exception ex) { throw new WebFaultException <string>(ex.Message, System.Net.HttpStatusCode.InternalServerError); } }