Esempio n. 1
0
        public IActionResult Register(RegisterViewModel auser)
        {
            string result   = "Success";
            var    context  = new masdatabaseContext();
            var    DataItem = context.Owner.Where(x => x.Email == auser.email).SingleOrDefault();

            if (DataItem != null)
            {
                result = "Fail";
            }
            else
            {
                string enpass  = Encryption.EncryptedPass(auser.password);
                var    adduser = new Owner {
                    Email = auser.email, Password = enpass, Name = auser.name, Surname = auser.surname, Tel = auser.tel
                };
                context.Add(adduser);
                context.SaveChanges();

                SqlConnection sqlcon = new SqlConnection("Data Source=(LocalDb)\\MSSQLLocalDb;Initial Catalog=MasSql;Integrated Security=True");
                sqlcon.Open();
                string     query1  = "INSERT INTO owner (Email, Password, Name, Surname , Tel) VALUES('" + auser.email + "', '" + enpass + "', '" + auser.name + "','" + auser.surname + "','" + auser.tel + "')";
                SqlCommand sqlcom1 = new SqlCommand(query1);
                sqlcom1.Connection = sqlcon;
                SqlDataReader sqlReader1 = sqlcom1.ExecuteReader();
                result = "OK";
                sqlcon.Close();
            }

            return(Json(result));
        }
Esempio n. 2
0
        public IActionResult set0Status(int status, int did)
        {
            string      result = "Fail";
            CultureInfo ci     = CultureInfo.InstalledUICulture;

            if (HttpContext.Session.GetInt32("Oid") == null)
            {
                return(RedirectToAction("Login", "User"));
            }
            else
            {
                var context = new masdatabaseContext();
                if (status != 0)
                {
                    var editstatus = context.Room.First(a => a.Rid == status);
                    editstatus.Tid    = 0;
                    editstatus.Status = "0";
                    context.SaveChanges();
                    var editrenter = context.Renter.First(a => a.Rid == status);
                    editrenter.RenName         = null;
                    editrenter.RenSurename     = null;
                    editrenter.RenTel          = null;
                    editrenter.RenAge          = null;
                    editrenter.RenSsnPicture   = null;
                    editrenter.StartElecMeter  = null;
                    editrenter.StartWaterMeter = null;
                    editrenter.RenAgreement    = null;
                    if (ci.ThreeLetterWindowsLanguageName == "THA")
                    {
                        editrenter.DateTime = Convert.ToDateTime("0544-01-01");
                    }
                    else
                    {
                        editrenter.DateTime = Convert.ToDateTime("0001-01-01");
                    }
                    context.SaveChanges();
                    result = "Update OK";
                }
            }
            return(Json(result));
        }
Esempio n. 3
0
        public IActionResult set1Status(int status)
        {
            string result = "Fail";

            if (HttpContext.Session.GetInt32("Oid") == null)
            {
                return(RedirectToAction("Login", "User"));
            }
            else
            {
                var context = new masdatabaseContext();
                if (status != 0)
                {
                    var editstatus = context.Room.First(a => a.Rid == status);
                    editstatus.Status = "1";
                    context.SaveChanges();
                    result = "Update OK";
                }
            }
            return(Json(result));
        }
Esempio n. 4
0
 public IActionResult EditRenter(myRenter renter, int did, int tid, IFormFile ssn, IFormFile agreement)
 {
     if (HttpContext.Session.GetInt32("Oid") == null)
     {
         return(RedirectToAction("Login", "User"));
     }
     {
         var ssnName       = "";
         var agreementName = "";
         if (ssn != null)
         {
             var uploads = Path.Combine(he.WebRootPath, "uploads\\img_ssn");
             ssnName = Guid.NewGuid().ToString().Substring(0, 10) + Path.GetExtension(ssn.FileName);
             ssn.CopyTo(new FileStream(Path.Combine(uploads, ssnName), FileMode.Create));
         }
         if (agreement != null)
         {
             var uploads = Path.Combine(he.WebRootPath, "uploads\\agreement");
             agreementName = Guid.NewGuid().ToString().Substring(0, 10) + Path.GetExtension(agreement.FileName);
             agreement.CopyTo(new FileStream(Path.Combine(uploads, agreementName), FileMode.Create));
         }
         int mydid   = did;
         var context = new masdatabaseContext();
         if (ssn == null & agreement == null)
         {
             var editroomtype = context.Room.First(b => b.Rid == renter.Rid);
             editroomtype.Tid = tid;
             context.SaveChanges();
             var editrenter = context.Renter.First(a => a.RenId == renter.RenId);
             editrenter.RenName         = renter.RenName;
             editrenter.RenSurename     = renter.RenSurename;
             editrenter.RenAge          = renter.RenAge;
             editrenter.RenTel          = renter.RenTel;
             editrenter.StartWaterMeter = renter.StartWaterMeter;
             editrenter.StartElecMeter  = renter.StartElecMeter;
             context.SaveChanges();
             TempData["EditSuccessful"] = "<script>swal({type: 'success', title: 'แก้ไขข้อมูลผู้เช่าสำเร็จ', showConfirmButton: false,  timer: 1500,backdrop: 'rgba(0,0, 26,0.8)' })</script>";
         }
         else if (ssn == null & agreement != null)
         {
             var editroomtype = context.Room.First(b => b.Rid == renter.Rid);
             editroomtype.Tid = tid;
             context.SaveChanges();
             var editrenter = context.Renter.First(a => a.RenId == renter.RenId);
             editrenter.RenName         = renter.RenName;
             editrenter.RenSurename     = renter.RenSurename;
             editrenter.RenAge          = renter.RenAge;
             editrenter.RenTel          = renter.RenTel;
             editrenter.StartWaterMeter = renter.StartWaterMeter;
             editrenter.StartElecMeter  = renter.StartElecMeter;
             editrenter.RenAgreement    = agreementName;
             context.SaveChanges();
             TempData["EditSuccessful"] = "<script>swal({type: 'success', title: 'แก้ไขข้อมูลผู้เช่าสำเร็จ', showConfirmButton: false,  timer: 1500,backdrop: 'rgba(0,0, 26,0.8)' })</script>";
         }
         else if (ssn != null & agreement == null)
         {
             var editroomtype = context.Room.First(b => b.Rid == renter.Rid);
             editroomtype.Tid = tid;
             context.SaveChanges();
             var editrenter = context.Renter.First(a => a.RenId == renter.RenId);
             editrenter.RenName         = renter.RenName;
             editrenter.RenSurename     = renter.RenSurename;
             editrenter.RenAge          = renter.RenAge;
             editrenter.RenTel          = renter.RenTel;
             editrenter.StartWaterMeter = renter.StartWaterMeter;
             editrenter.StartElecMeter  = renter.StartElecMeter;
             editrenter.RenSsnPicture   = ssnName;
             context.SaveChanges();
             TempData["EditSuccessful"] = "<script>swal({type: 'success', title: 'แก้ไขข้อมูลผู้เช่าสำเร็จ', showConfirmButton: false,  timer: 1500,backdrop: 'rgba(0,0, 26,0.8)' })</script>";
         }
         else if (ssn != null & agreement != null)
         {
             var editroomtype = context.Room.First(b => b.Rid == renter.Rid);
             editroomtype.Tid = tid;
             context.SaveChanges();
             var editrenter = context.Renter.First(a => a.RenId == renter.RenId);
             editrenter.RenName         = renter.RenName;
             editrenter.RenSurename     = renter.RenSurename;
             editrenter.RenAge          = renter.RenAge;
             editrenter.RenTel          = renter.RenTel;
             editrenter.StartWaterMeter = renter.StartWaterMeter;
             editrenter.StartElecMeter  = renter.StartElecMeter;
             editrenter.RenSsnPicture   = ssnName;
             editrenter.RenAgreement    = agreementName;
             context.SaveChanges();
             TempData["EditSuccessful"] = "<script>swal({type: 'success', title: 'แก้ไขข้อมูลผู้เช่าสำเร็จ', showConfirmButton: false,  timer: 1500,backdrop: 'rgba(0,0, 26,0.8)' })</script>";
         }
         return(RedirectToAction("ShowRoom", "Renter", new { did = mydid }));
     }
 }
Esempio n. 5
0
        public IActionResult EditProfiles(ProfileEdit pf, IFormFile picture)
        {
            var context = new masdatabaseContext();

            if (HttpContext.Session.GetInt32("Oid") == null)
            {
                return(RedirectToAction("Login", "User"));
            }
            else
            {
                SqlConnection sqlcon = new SqlConnection("Data Source=(LocalDb)\\MSSQLLocalDb;Initial Catalog=MasSql;Integrated Security=True");
                if (picture != null)
                {
                    var fileName = "";
                    var uploads  = Path.Combine(he.WebRootPath, "uploads\\img_profile");
                    fileName = Guid.NewGuid().ToString().Substring(0, 10) + Path.GetExtension(picture.FileName);
                    picture.CopyTo(new FileStream(Path.Combine(uploads, fileName), FileMode.Create));

                    if (pf.Picture != null)
                    {
                        var editOwner = context.Owner.First(a => a.Oid == HttpContext.Session.GetInt32("Oid"));
                        editOwner.Name    = pf.Name;
                        editOwner.Surname = pf.Surname;
                        editOwner.Tel     = pf.Tel;
                        context.SaveChanges();
                        sqlcon.Open();
                        string     query1  = "UPDATE owner SET Name='" + pf.Name + "',Surname='" + pf.Surname + "',Tel='" + pf.Tel + "' WHERE Oid = " + HttpContext.Session.GetInt32("Oid") + " ";
                        SqlCommand sqlcom1 = new SqlCommand(query1);
                        sqlcom1.Connection = sqlcon;
                        SqlDataReader sqlReader1 = sqlcom1.ExecuteReader();
                        sqlcon.Close();
                        TempData["EditSuccessful"] = "<script>swal({type: 'success', title: 'แก้ไขข้อมูลสำเร็จ', showConfirmButton: false,  timer: 1500,backdrop: 'rgba(0,0, 26,0.8)' })</script>";
                        HttpContext.Session.SetString("Name", pf.Name);
                        HttpContext.Session.SetString("Surname", pf.Surname);
                        HttpContext.Session.SetString("Tel", pf.Tel);
                        return(RedirectToAction("ManageDorm", "Manage"));
                    }
                    else
                    {
                        var editOwner = context.Owner.First(a => a.Oid == HttpContext.Session.GetInt32("Oid"));
                        editOwner.Name    = pf.Name;
                        editOwner.Surname = pf.Surname;
                        editOwner.Tel     = pf.Tel;
                        editOwner.Picture = fileName;
                        context.SaveChanges();
                        sqlcon.Open();
                        string     query1  = "UPDATE owner SET Name='" + pf.Name + "',Surname='" + pf.Surname + "',Tel='" + pf.Tel + "',Picture='" + fileName + "' WHERE Oid = " + HttpContext.Session.GetInt32("Oid") + " ";
                        SqlCommand sqlcom1 = new SqlCommand(query1);
                        sqlcom1.Connection = sqlcon;
                        SqlDataReader sqlReader1 = sqlcom1.ExecuteReader();
                        sqlcon.Close();
                        TempData["EditSuccessful"] = "<script>swal({type: 'success', title: 'แก้ไขข้อมูลสำเร็จ', showConfirmButton: false,  timer: 1500,backdrop: 'rgba(0,0, 26,0.8)' })</script>";
                        HttpContext.Session.SetString("Name", pf.Name);
                        HttpContext.Session.SetString("Surname", pf.Surname);
                        HttpContext.Session.SetString("Tel", pf.Tel);
                        HttpContext.Session.SetString("Picture", fileName);
                        return(RedirectToAction("ManageDorm", "Manage"));
                    }
                }
                else
                {
                    if (pf.Picture != null)
                    {
                        var editOwner = context.Owner.First(a => a.Oid == HttpContext.Session.GetInt32("Oid"));
                        editOwner.Name    = pf.Name;
                        editOwner.Surname = pf.Surname;
                        editOwner.Tel     = pf.Tel;
                        context.SaveChanges();
                        sqlcon.Open();
                        string     query1  = "UPDATE owner SET Name='" + pf.Name + "',Surname='" + pf.Surname + "',Tel='" + pf.Tel + "' WHERE Oid = " + HttpContext.Session.GetInt32("Oid") + " ";
                        SqlCommand sqlcom1 = new SqlCommand(query1);
                        sqlcom1.Connection = sqlcon;
                        SqlDataReader sqlReader1 = sqlcom1.ExecuteReader();
                        sqlcon.Close();
                        TempData["EditSuccessful"] = "<script>swal({type: 'success', title: 'แก้ไขข้อมูลสำเร็จ', showConfirmButton: false,  timer: 1500,backdrop: 'rgba(0,0, 26,0.8)' })</script>";
                        HttpContext.Session.SetString("Name", pf.Name);
                        HttpContext.Session.SetString("Surname", pf.Surname);
                        HttpContext.Session.SetString("Tel", pf.Tel);
                        return(RedirectToAction("ManageDorm", "Manage"));
                    }
                    else
                    {
                        var editOwner = context.Owner.First(a => a.Oid == HttpContext.Session.GetInt32("Oid"));
                        editOwner.Name    = pf.Name;
                        editOwner.Surname = pf.Surname;
                        editOwner.Tel     = pf.Tel;
                        context.SaveChanges();
                        sqlcon.Open();
                        string     query1  = "UPDATE owner SET Name='" + pf.Name + "',Surname='" + pf.Surname + "',Tel='" + pf.Tel + "' WHERE Oid = " + HttpContext.Session.GetInt32("Oid") + " ";
                        SqlCommand sqlcom1 = new SqlCommand(query1);
                        sqlcom1.Connection = sqlcon;
                        SqlDataReader sqlReader1 = sqlcom1.ExecuteReader();
                        sqlcon.Close();
                        TempData["EditSuccessful"] = "<script>swal({type: 'success', title: 'แก้ไขข้อมูลสำเร็จ', showConfirmButton: false,  timer: 1500,backdrop: 'rgba(0,0, 26,0.8)' })</script>";
                        HttpContext.Session.SetString("Name", pf.Name);
                        HttpContext.Session.SetString("Surname", pf.Surname);
                        HttpContext.Session.SetString("Tel", pf.Tel);
                        return(RedirectToAction("ManageDorm", "Manage"));
                    }
                }
            }
        }