Esempio n. 1
0
        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));
            }
        }
Esempio n. 2
0
        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"));
            }
        }
Esempio n. 3
0
 public void End()
 {
     using (var db = new db_context())
     {
         db.Database.ExecuteSqlCommand("TRUNCATE TABLE [Table_1]");
     }
 }
Esempio n. 4
0
 public void Start()
 {
     using (var db = new db_context())
     {
         db.Osoby.Add(new Osoba("Pawel", "Kajka", 25));
         db.SaveChanges();
     }
 }
Esempio n. 5
0
 public ActionResult Details(int IDOsoby)
 {
     using (var db = new db_context())
     {
         Osoba o = db.Osoby.Find(IDOsoby);
         return(View(o));
     }
 }
Esempio n. 6
0
 public PartialViewResult Mails()
 {
     using (var db = new db_context())
     {
         var maile = db.Adresy.ToList();
         return(PartialView(maile));
     }
 }
Esempio n. 7
0
        public List <TransacaoModel> Retornatransacoes()
        {
            using (var context = new db_context())
            {
                var retorno = context.TransacaoModels.ToList();

                return(retorno);
            }
        }
Esempio n. 8
0
 public ActionResult Add(Nieruchomosc model)
 {
     using (var db = new db_context())
     {
         db.Nieruchomosci.Add(model);
         db.SaveChanges();
         return(RedirectToAction("Index", "Osoby"));
     }
 }
Esempio n. 9
0
        public PartialViewResult MapPartial(int ID)
        {
            using (var db = new db_context())
            {
                var nieruchomosc = db.Nieruchomosci.FirstOrDefault(x => x.ID == ID);

                return(PartialView(nieruchomosc));
            }
        }
Esempio n. 10
0
        //[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));
            }
        }
Esempio n. 11
0
        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));
            }
        }
Esempio n. 12
0
        public void AddGetTest()
        {
            using (var db = new db_context())
            {
                var ctrl = new OsobyController();
                var add  = ctrl.Add();

                Assert.IsInstanceOf(typeof(ViewResult), add);
            }
        }
Esempio n. 13
0
        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);
            }
        }
Esempio n. 14
0
        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);
            }
        }
Esempio n. 15
0
        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);
            }
        }
Esempio n. 16
0
        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);
            }
        }
Esempio n. 17
0
        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);
            }
        }
Esempio n. 18
0
        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));
            }
        }
Esempio n. 19
0
        public ActionResult Remove(MailAdress model)
        {
            using (var db = new db_context())
            {
                db.Adresy.Attach(model);
                db.Adresy.Remove(model);

                db.SaveChanges();

                return(RedirectToAction("Index"));
            }
        }
Esempio n. 20
0
 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();
         }
     }
 }
Esempio n. 21
0
        // 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));
            }
        }
Esempio n. 22
0
        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);
            }
        }
Esempio n. 23
0
        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"));
        }
Esempio n. 24
0
        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();
            }
        }
Esempio n. 25
0
        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);
            }
        }
Esempio n. 26
0
        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);
            }
        }
Esempio n. 27
0
        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);
            }
        }
Esempio n. 28
0
        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());
            }
        }
Esempio n. 29
0
 public void AdicionaTransacao(TransacaoModel transacao)
 {
     try
     {
         using (var context = new db_context())
         {
             context.TransacaoModels.Add(transacao);
             context.SaveChanges();
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
Esempio n. 30
0
        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);
            }
        }