public ActionResult Edit(Osoba model) { if (model != null && ModelState.IsValid) { using (var db = new db_context()) { Osoba o = db.Osoby.Find(model.ID); if (o != null) { foreach (var p in o.GetType().GetProperties()) { if (!o.HasPropertyAttribute(p.Name, typeof(KeyAttribute))) { p.SetValue(o, model.GetType().GetProperty(p.Name).GetValue(model)); } } } db.SaveChanges(); } return(RedirectToAction("Index")); } else { return(View(model)); } }
public ActionResult WyslijMail_Click(Email model) { using (var db = new db_context()) { string Sub = model.Subject; string Bod = model.Body; if (Sub != null && Bod != null) { MailMessage mail = new MailMessage(); mail.From = new System.Net.Mail.MailAddress("*****@*****.**"); foreach (var adres in db.Adresy) { mail.To.Add(new System.Net.Mail.MailAddress(adres.Adres)); } SmtpClient client = new SmtpClient(); client.Port = 587; client.EnableSsl = true; client.DeliveryMethod = SmtpDeliveryMethod.Network; client.UseDefaultCredentials = false; client.Host = "smtp.gmail.com"; mail.Subject = Sub; mail.Body = Bod; mail.IsBodyHtml = true; client.Credentials = new NetworkCredential("*****@*****.**", "Abcdefgh123"); client.Send(mail); } return(RedirectToAction("Index")); } }
public void End() { using (var db = new db_context()) { db.Database.ExecuteSqlCommand("TRUNCATE TABLE [Table_1]"); } }
public void Start() { using (var db = new db_context()) { db.Osoby.Add(new Osoba("Pawel", "Kajka", 25)); db.SaveChanges(); } }
public ActionResult Details(int IDOsoby) { using (var db = new db_context()) { Osoba o = db.Osoby.Find(IDOsoby); return(View(o)); } }
public PartialViewResult Mails() { using (var db = new db_context()) { var maile = db.Adresy.ToList(); return(PartialView(maile)); } }
public List <TransacaoModel> Retornatransacoes() { using (var context = new db_context()) { var retorno = context.TransacaoModels.ToList(); return(retorno); } }
public ActionResult Add(Nieruchomosc model) { using (var db = new db_context()) { db.Nieruchomosci.Add(model); db.SaveChanges(); return(RedirectToAction("Index", "Osoby")); } }
public PartialViewResult MapPartial(int ID) { using (var db = new db_context()) { var nieruchomosc = db.Nieruchomosci.FirstOrDefault(x => x.ID == ID); return(PartialView(nieruchomosc)); } }
//[HttpGet] //[ActionName("Pokaz")] nadpisanie nazwy //[NonAction] ukrycie akcji public JsonResult GetNieruchomosci(int IDOsoby) { using (var db = new db_context()) { var nieruchomosci = db.Nieruchomosci.Where(x => x.IDOsoby == IDOsoby).ToList(); return(Json(nieruchomosci, JsonRequestBehavior.AllowGet)); } }
public ActionResult Edit(int id) { using (var db = new db_context()) { Osoba o = db.Osoby.Find(id); //o = o == null ? new Osoba() : o; return(View(o)); } }
public void AddGetTest() { using (var db = new db_context()) { var ctrl = new OsobyController(); var add = ctrl.Add(); Assert.IsInstanceOf(typeof(ViewResult), add); } }
public void GetJsonTest() { using (var db = new db_context()) { var ctrl = new NieruchmoscController(); int id = db.Osoby.First().ID; var json = ctrl.GetNieruchomosci(id); Assert.IsInstanceOf(typeof(JsonResult), json); } }
public void AddGetTest() { using (var db = new db_context()) { int id = db.Osoby.First().ID; var ctrl = new NieruchmoscController(); var add = ctrl.Add(id); //add Nie pobiera lczby argumentów Assert.IsInstanceOf(typeof(ViewResult), add); } }
public void EditGetTest() { using (var db = new db_context()) { int id = db.Osoby.First().ID; var ctrl = new OsobyController(); var edit = ctrl.Edit(id); Assert.IsInstanceOf(typeof(ViewResult), edit); } }
public TransacaoModel RetornaListTransacoesDetalhes() { using (var context = new db_context()) { TransacaoModel transacao = new TransacaoModel(); transacao.MoedaModel = context.MoedaModels.ToList(); transacao.TipoTransacaoModel = context.TipoTransacaoModels.ToList(); return(transacao); } }
public void RemoveTypeTest() { using (var db = new db_context()) { var model = db.Osoby.First(); var ctrl = new OsobyController(); var remove = ctrl.Remove(model); Assert.IsInstanceOf(typeof(ActionResult), remove); } }
public ActionResult Add() { using (var db = new db_context()) { Osoba o = new Osoba(); o = db.Osoby.Add(o); //o = o == null ? new Osoba() : o; return(View(o)); } }
public ActionResult Remove(MailAdress model) { using (var db = new db_context()) { db.Adresy.Attach(model); db.Adresy.Remove(model); db.SaveChanges(); return(RedirectToAction("Index")); } }
public void ValidaLogin(LoginModel loginModel) { using (var context = new db_context()) { var xai = context.LoginModels.ToList(); var user = context.LoginModels.Where(l => l.Usuario == loginModel.Usuario && l.Senha == loginModel.Senha).FirstOrDefault(); if (user == null) { throw new Exception(); } } }
// GET: Osoby //[HttpGet] public ActionResult Index(string pole) { using (var db = new db_context()) { List <Osoba> osoby = Sortuj(db, pole); ViewBag.Title = "Osoby na dzień " + DateTime.Now.ToShortDateString(); ViewData["ObecnyTytul"] = "Osoby na dzień " + DateTime.Now.ToShortDateString(); return(View(osoby)); } }
public void MapPartialTest() { using (var db = new db_context()) { var ctrl = new NieruchmoscController(); int ID = 0; var nieruchomosc = db.Nieruchomosci.FirstOrDefault(x => x.ID == ID); var map = ctrl.MapPartial(ID); Assert.IsInstanceOf(typeof(PartialViewResult), map); } }
public ActionResult Import(HttpPostedFileBase file) { if (file != null) { string filename = file.FileName; string targetpath = Server.MapPath("~/App_Data/"); file.SaveAs(targetpath + filename); string pathToExcelFile = targetpath + filename; string connectionString = ""; if (file.FileName.EndsWith(".xls")) { connectionString = string.Format("Provider=Microsoft.Jet.OLEDB.4.0; data source={0}; Extended Properties=Excel 8.0;", pathToExcelFile); } else if (file.FileName.EndsWith(".xlsx")) { connectionString = string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=\"Excel 12.0 Xml;HDR=YES;IMEX=1\";", pathToExcelFile); } else { return(RedirectToAction("Index")); } var adapter = new OleDbDataAdapter("Select * FROM [Arkusz1$]", connectionString); var ds = new DataSet(); adapter.Fill(ds, "ExcelTable"); DataTable dtable = ds.Tables["ExcelTable"]; using (var db = new db_context()) { foreach (DataRow dr in dtable.Rows) { Osoba o = new Osoba(); o.Imie = dr[0].ToString(); o.Nazwisko = dr[1].ToString(); o.Wiek = Int32.Parse(dr[2].ToString()); o.Zdjecie = dr[3].ToString(); db.Osoby.Add(o); } db.SaveChanges(); } if ((System.IO.File.Exists(pathToExcelFile))) { System.IO.File.Delete(pathToExcelFile); } } return(RedirectToAction("Index")); }
protected void Application_BeginRequest() { using (var db = new db_context()) { db.HistoriaTable.Add(new Historia() { Date = DateTime.Now, Action = HttpContext.Current.Request.Url.OriginalString }); db.SaveChanges(); } }
public void EditPostTypeTest() { using (var db = new db_context()) { Osoba model = db.Osoby.First(); model.Imie = "Zacheusz"; model.Nazwisko = "Olek"; model.Wiek = 99; var ctrl = new OsobyController(); var edit = ctrl.Edit(model); Assert.IsInstanceOf(typeof(ActionResult), edit); } }
public void AddPostTypeTest() { using (var db = new db_context()) { Osoba model = new Osoba(); model.Imie = "Zbyszek"; model.Nazwisko = "Erbal"; model.Wiek = 94; var ctrl = new OsobyController(); var add = ctrl.Add(model); Assert.IsInstanceOf(typeof(ActionResult), add); } }
public void EditPostTest() { using (var db = new db_context()) { Osoba model = db.Osoby.First(); model.Imie = "Zacheusz"; model.Nazwisko = "Olek"; model.Wiek = 99; var ctrl = new OsobyController(); var edit = ctrl.Edit(model); var modelUpdated = db.Osoby.First(x => x.ID == model.ID); Assert.IsTrue(modelUpdated.Imie == model.Imie && modelUpdated.Nazwisko == model.Nazwisko && modelUpdated.Wiek == model.Wiek); } }
private static List <Osoba> Sortuj(db_context db, string pole) { pole = pole != null ? pole : ""; PropertyInfo prop = typeof(Osoba).GetProperty(pole); if (prop != null) { return(db.Osoby.ToList().OrderBy(x => prop.GetValue(x, null)).ToList()); } else { return(db.Osoby.ToList()); } }
public void AdicionaTransacao(TransacaoModel transacao) { try { using (var context = new db_context()) { context.TransacaoModels.Add(transacao); context.SaveChanges(); } } catch (Exception) { throw; } }
public void AddPostTest() { using (var db = new db_context()) { Osoba model = new Osoba(); model.Imie = "Zbyszek"; model.Nazwisko = "Erbal"; model.Wiek = 94; var ctrl = new OsobyController(); var add = ctrl.Add(model); bool exist = db.Osoby.Any(x => x.Imie == model.Imie && x.Nazwisko == model.Nazwisko && x.Wiek == model.Wiek); Assert.IsTrue(exist); } }