Esempio n. 1
0
        public JsonResult ActionCreate(string ffName)
        {
            try
            {
                dynamic         item = JsonConvert.DeserializeObject(ffName);
                channelEntities tfn  = new channelEntities();
                user            p1   = new user();
                p1.username = item.user;
                p1.password = item.pass;
                p1.room     = item.roo;
                tfn.users.Add(p1);
                tfn.SaveChanges();

                //pro1Entities1 tfn = new pro1Entities1();

                //fullname p1 = new fullname();
                //p1.firstName = item.fName;
                //p1.lastName = item.lName;
                //tfn.fullnames.Add(p1);
                //tfn.SaveChanges();

                return(Json(new { status = "200", message = "success" }));
            }
            catch (Exception ex)
            {
                return(Json(new { status = "500", message = ex.Message }));
            }
        }
Esempio n. 2
0
 public JsonResult Logout()
 {
     try
     {
         string          test  = Session["ID"].ToString();
         channelEntities p1    = new channelEntities();
         user            model = p1.users.FirstOrDefault(x => x.userName == test);
         model.status     = false;
         Session["login"] = false;
         p1.SaveChanges();
         return(Json(new { status = "200", message = "success" }));
     } catch (Exception ex)
     { return(Json(new { status = "500", message = ex.Message })); }
 }
Esempio n. 3
0
        public ActionResult Login(string ffName)
        {
            try
            {
                dynamic         item    = JsonConvert.DeserializeObject(ffName);
                string          fName   = item.fName;
                string          lName   = item.lName;
                channelEntities p1      = new channelEntities();
                classPro1       modelP1 = new classPro1();
                modelP1.users = (
                    from full in p1.users.AsEnumerable()
                    where full.userName == fName && full.userPass == lName
                    select new
                {
                    userName1 = full.userName,
                    userPass1 = full.userPass
                }).First();



                if (modelP1.users != null)
                {
                    Session["ID"]   = fName;
                    Session["PASS"] = lName;
                    user model = p1.users.FirstOrDefault(x => x.userName == fName && x.userPass == lName);
                    model.status     = true;
                    Session["login"] = true;
                    p1.SaveChanges();

                    return(Json(new { status = "200", message = "success" }));
                }
                else
                {
                    Session["login"] = false;
                    return(Json(new { status = "500", message = "cannot login" }));
                }
            }
            catch (Exception ex)
            {
                Session["login"] = false;
                return(Json(new { status = "500", message = ex.Message }));
            }
        }
Esempio n. 4
0
        public JsonResult ActionCreate(string ffName)
        {
            try
            {
                dynamic item = JsonConvert.DeserializeObject(ffName);

                channelEntities tfn = new channelEntities();

                user p1 = new user();
                p1.userName = item.fName;
                p1.userPass = item.lName;
                tfn.users.Add(p1);
                tfn.SaveChanges();

                return(Json(new { status = "200", message = "success" }));
            }
            catch (Exception ex)
            {
                return(Json(new { status = "500", message = ex.Message }));
            }
        }
Esempio n. 5
0
        public JsonResult ImageUpload(string Account)
        {
            try
            {
                channelEntities pro1Entities = new channelEntities();
                dynamic         data         = JsonConvert.DeserializeObject(Account);
                room            albums       = new room();
                albums.NamePhoto = data.Album;
                albums.cName     = data.id.ToString();
                albums.cPass     = data.pass.ToString();
                //albums.CreateAt = DateTime.Now;
                pro1Entities.rooms.Add(albums);
                pro1Entities.SaveChanges();
                Directory.CreateDirectory(Server.MapPath("~/Photos/" + albums.cID));


                int i = 1;
                foreach (dynamic items in data.img)
                {
                    // Convert Base64 String to byte[]
                    string[]     words      = (items.fileName).ToString().Split(',');
                    byte[]       imageBytes = Convert.FromBase64String(words[1]);
                    MemoryStream ms         = new MemoryStream(imageBytes, 0, imageBytes.Length);

                    // Convert byte[] to Image
                    ms.Write(imageBytes, 0, imageBytes.Length);
                    System.Drawing.Image image = System.Drawing.Image.FromStream(ms, true);
                    string newFile             = i + ".jpg";
                    string filePath            = Path.Combine(Server.MapPath("~/Photos/" + albums.cID), newFile);
                    //string filePath = Path.Combine(Server.MapPath(@"~C:\Photos\" + albums.IDAlbum), newFile);
                    //string vPath = filePath.Replace(@"C:\code", "~").Replace(@"\", "/");
                    string dbPathImageMore = "/Photos/" + albums.cID.ToString() + "/" + newFile;



                    image.Save(filePath, ImageFormat.Jpeg);
                    //HttpContextBase
                    string currentUrl = System.Web.HttpContext.Current.Request.Url.ToString().ToLower();
                    if (currentUrl.Contains("localhost"))   //  เป็น  version ทำในเครื่องหรือป่าว
                    {
                        //trucur = "yes";   // ถ้าทำในเครื่อง
                    }
                    else
                    {
                        //nocur = "no";     // version deploy
                    }
                    //rooms photostock = new rooms();
                    //photostock.NamePhoto1 = dbPathImageMore;
                    //photostock.cID1 = albums.cID;
                    //pro1Entities.rooms.Add(photostock);
                    //user model = p1.users.FirstOrDefault(x => x.userName == fName && x.userPass == lName);
                    //model.status = true;
                    //Session["login"] = true;
                    //p1.SaveChanges();
                    i++;
                }
                pro1Entities.SaveChanges();
                return(Json(new { status = "200", message = "Success" }));
            }
            catch (Exception ex)
            {
                return(Json(new { status = "500", message = ex.Message }));
            }
        }