public IHttpActionResult Putcomment(int id, comment comment)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != comment.commentId)
            {
                return(BadRequest());
            }

            db.Entry(comment).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!commentExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Beispiel #2
0
        public ActionResult EmailConfirmed(ChangePassword chng)
        {
            string password = chng.password;

            if (TempData["id"] != null)
            {
                int          id      = int.Parse(TempData["id"].ToString());
                user         us      = context.users.Find(id);
                passwordHash hash    = new passwordHash();
                string       newpass = hash.CreateMd5(chng.password);
                var          user    = new user {
                    id = id, password = newpass
                };
                using (var db = new socialEntities())
                {
                    db.users.Attach(user);
                    db.Entry(user).Property(x => x.password).IsModified = true;
                    db.SaveChanges();
                }
                TempData["id"] = us.id;
                HttpCookie userId = new HttpCookie("id");
                userId.Value   = us.id.ToString();
                userId.Expires = DateTime.Now.AddHours(2);
                HttpContext.Response.SetCookie(userId);
                Session["User" + us.id] = us;
                return(Redirect("/Profile/Index/"));
            }
            return(View());
        }
Beispiel #3
0
        public void  ChangeProfile(int id)
        {
            string   currid = Request.Params["id"].ToString();
            user     us     = Session["User" + currid] as user;
            NewsFeed feed   = db.NewsFeeds.Find(id);
            var      user   = new user {
                id = us.id, profile_photo = feed.photos
            };

            using (var db = new socialEntities())
            {
                db.users.Attach(user);
                db.Entry(user).Property(x => x.profile_photo).IsModified = true;
                try
                {
                    //add to feed
                    NewsFeed feeds = new NewsFeed();
                    feeds.dateTime     = DateTime.Now;
                    feeds.user_id      = us.id;
                    feeds.photos       = feed.photos;
                    feeds.feedState_id = 6;
                    db.NewsFeeds.Add(feeds);
                    db.SaveChanges();
                }
                catch (Exception e)
                {
                    string st = e.Message;
                }
            }
        }
Beispiel #4
0
        public ActionResult FacebookCallback(string code)

        {
            var fb = new FacebookClient();

            dynamic result = fb.Post("oauth/access_token", new

            {
                client_id = "2324915974199076",

                client_secret = "64f8416b5e2aa304cf40ae38770cc36a",

                redirect_uri = RedirectUri.AbsoluteUri,

                code = code
            });

            var accessToken = result.access_token;

            Session["AccessToken"] = accessToken;

            fb.AccessToken = accessToken;

            dynamic me = fb.Get("me?fields=link,first_name,currency,last_name,email,gender,locale,timezone,verified,picture,age_range");

            string      email = me.email;
            List <user> users = db.users.Where(usr => usr.email == email).ToList();

            if (users.Count == 0)
            {
                user us = new user();
                us.email         = me.email;
                us.name          = me.first_name;
                us.surname       = me.last_name;
                us.from_facebook = 1;
                us.profile_photo = "~/Content/Backgrounds/images.png";
                db.users.Add(us);
                db.SaveChanges();
                Session["User" + us.id] = us;
                TempData["id"]          = us.id;
                HttpCookie userId = new HttpCookie("id");
                userId.Value   = us.id.ToString();
                userId.Expires = DateTime.Now.AddHours(2);
                HttpContext.Response.SetCookie(userId);
                FormsAuthentication.SetAuthCookie(email, false);
                return(RedirectToAction("Index", "Profile"));
            }
            else
            {
                FormsAuthentication.SetAuthCookie(email, false);
                Session["User" + users[0].id] = users[0];
                HttpCookie userId = new HttpCookie("id");
                userId.Value   = users[0].id.ToString();
                userId.Expires = DateTime.Now.AddHours(2);
                HttpContext.Response.SetCookie(userId);
                TempData["id"] = users[0].id;
                return(RedirectToAction("Index", "Profile"));
            }
        }
Beispiel #5
0
        public void GetFeedback(int id)
        {
            NewsFeed feed     = new NewsFeed();
            NewsFeed newsfeed = db.NewsFeeds.Find(id);
            string   currid   = Request.Params["id"].ToString();
            user     us       = Session["User" + currid] as user;
            int      val      = int.Parse(Request.Params["value"].ToString());

            feed.on_feed_id   = id;
            feed.dateTime     = DateTime.Now;
            feed.feedState_id = 8;
            feed.user_id      = us.id;
            notification_text text = new notification_text();

            if (val == 1)
            {
                feed.contetnfeed = db.notification_text.Find(11).notification_text1.ToString();
            }
            else if (val == 2)
            {
                feed.contetnfeed = db.notification_text.Find(12).notification_text1.ToString();
            }
            else if (val == 3)
            {
                feed.contetnfeed = db.notification_text.Find(13).notification_text1.ToString();
            }
            else if (val == 4)
            {
                feed.contetnfeed = db.notification_text.Find(14).notification_text1.ToString();
            }
            else if (val == 5)
            {
                feed.contetnfeed = db.notification_text.Find(15).notification_text1.ToString();
            }
            db.NewsFeeds.Add(feed);
            db.SaveChanges();
        }
Beispiel #6
0
        public async void UnBlock(string id)
        {
            int  iD  = int.Parse(id);
            user usr = await db.users.FindAsync(iD);

            var user = new user {
                id = iD, is_blocked = 0
            };

            using (var db = new socialEntities())
            {
                db.users.Attach(user);
                db.Entry(user).Property(x => x.is_blocked).IsModified = true;
                db.SaveChanges();
            }
        }
Beispiel #7
0
        public ActionResult ChangeColor(int id)
        {
            string currid = Request.Params["id"].ToString();
            user   us     = Session["User" + currid] as user;
            string color  = Request.Params["color"].ToString();
            var    user   = new user {
                id = us.id, color = color
            };

            using (var db = new socialEntities())
            {
                db.users.Attach(user);
                db.Entry(user).Property(x => x.color).IsModified = true;
                db.SaveChanges();
            }
            return(Redirect("/Profile/Index/"));
        }
Beispiel #8
0
        public JsonResult ChangeExPas()
        {
            int          id      = int.Parse(Request.Params["id"].ToString());
            passwordHash hash    = new passwordHash();
            user         us      = db.users.Find(id);
            string       pasEx   = Request.Params["pasEx"].ToString();
            string       pas     = Request.Params["pas"].ToString();
            string       pasConf = Request.Params["pasConf"].ToString();

            if (pas != pasConf)
            {
                object res = new object();
                res = (new {
                    error = "passwods are not same",
                });
                return(Json(res, JsonRequestBehavior.AllowGet));
            }
            else if (hash.CreateMd5(pasEx) != us.password)
            {
                object res = new object();
                res = (new
                {
                    error = "enter correct password",
                });
                return(Json(res, JsonRequestBehavior.AllowGet));
            }
            else
            {
                var user = new user {
                    id = us.id, password = hash.CreateMd5(pas)
                };
                using (var db = new socialEntities())
                {
                    db.users.Attach(user);
                    db.Entry(user).Property(x => x.password).IsModified = true;
                    db.SaveChanges();
                }
                object res = new object();
                res = (new
                {
                    error = "success",
                });
                return(Json(res, JsonRequestBehavior.AllowGet));
            }
        }
Beispiel #9
0
 // GET: Auto_Notification_Sender
 public void Index()
 {
     foreach (user us in db.users)
     {
         if (us.stat == 1)
         {
             continue;
         }
         notification not = new notification();
         not.sender_id = 25;
         not.user_id   = us.id;
         not.text_id   = 9;
         not.state     = 1;
         not.datetime  = DateTime.Now;
         db.notifications.Add(not);
     }
     db.SaveChanges();
 }
Beispiel #10
0
        public void AddAdv(string id)
        {
            int    advId = int.Parse(id);
            string src   = Request.Params["src"].ToString();
            string cost  = Request.Params["cost"].ToString();
            string url   = Request.Params["url"].ToString();

            url = url.Replace(",/Admin/AddAdv/1", "");
            url = url.Replace(",/Admin/AddAdv/2", "");
            url = url.Replace(",/Admin/AddAdv/3", "");
            List <advert> ads = (from item in db.adverts where item.advNo == advId && item.status == 1 select item).ToList();

            if (ads.Count != 0)
            {
                var adv = new advert {
                    id = ads[0].id, advert1 = src, cost = int.Parse(cost), datetime = DateTime.Now, url = url
                };
                using (var db = new socialEntities())
                {
                    db.adverts.Attach(adv);
                    db.Entry(adv).Property(x => x.advert1).IsModified  = true;
                    db.Entry(adv).Property(x => x.cost).IsModified     = true;
                    db.Entry(adv).Property(x => x.url).IsModified      = true;
                    db.Entry(adv).Property(x => x.datetime).IsModified = true;
                    db.SaveChanges();
                }
            }
            else
            {
                advert ad = new advert();
                ad.advNo    = advId;
                ad.status   = 1;
                ad.advert1  = src;
                ad.url      = url;
                ad.datetime = DateTime.Now;
                ad.cost     = int.Parse(cost);
                db.adverts.Add(ad);
                db.SaveChanges();
            }
        }
Beispiel #11
0
        public JsonResult Redact()
        {
            int         id     = int.Parse(Request.Params["id"].ToString());
            user        us     = db.users.Find(id);
            string      name   = Request.Params["name"].ToString();
            string      suname = Request.Params["surname"].ToString();
            int         age    = int.Parse(Request.Params["age"].ToString());
            string      login  = Request.Params["login"].ToString();
            List <user> usrs   = db.users.Where(m => m.login == login).ToList();
            object      res    = new object();

            if (login.Length <= 6 && login != "0")
            {
                res = (new
                {
                    error = "login will contain more than 6 symbol",
                });
                return(Json(res, JsonRequestBehavior.AllowGet));
            }
            else if (usrs.Count > 0 && login != "0")
            {
                res = (new
                {
                    error = "login already excist choose another",
                });
                return(Json(res, JsonRequestBehavior.AllowGet));
            }
            if (name != "0" || suname != "0" || age.ToString() != "0")
            {
                if (name != "0")
                {
                    var user = new user {
                        id = us.id, name = name
                    };
                    using (var db = new socialEntities())
                    {
                        db.users.Attach(user);
                        db.Entry(user).Property(x => x.name).IsModified = true;
                        db.SaveChanges();
                    }
                }
                if (suname != "0")
                {
                    var user = new user {
                        id = us.id, surname = suname
                    };
                    using (var db = new socialEntities())
                    {
                        db.users.Attach(user);
                        db.Entry(user).Property(x => x.surname).IsModified = true;
                        db.SaveChanges();
                    }
                }
                if (age.ToString() != "0")
                {
                    var user = new user {
                        id = us.id, age = age
                    };
                    using (var db = new socialEntities())
                    {
                        db.users.Attach(user);
                        db.Entry(user).Property(x => x.age).IsModified = true;
                        db.SaveChanges();
                    }
                }
            }
            res = (new
            {
                error = "success",
            });
            return(Json(res, JsonRequestBehavior.AllowGet));
        }
Beispiel #12
0
        public async Task <ActionResult> Index(int id)
        {
            //add your shares into your newsfeed
            user     us       = Session["User" + id.ToString()] as user;
            follower folower1 = new follower();
            NewsFeed feed1    = new NewsFeed();

            if (Request.Params["area1"] != null && Request.Params["area1"].ToString() != "")
            {
                feed1.user_id      = us.id;
                feed1.contetnfeed  = Request.Params["area1"].ToString();
                feed1.dateTime     = DateTime.Now;
                feed1.feedState_id = 1;
                db.NewsFeeds.Add(feed1);
                db.SaveChanges();
                TempData["id"] = id;
                return(RedirectToAction("Index"));
            }
            TempData["id"] = id;
            return(RedirectToAction("Index"));
        }
Beispiel #13
0
        public async Task <ActionResult> SendMessage()
        {
            string currid = Request.Params["id"].ToString();

            if (Request.Params["admin-message"] != null)
            {
                string      text    = Request.Params["admin-message"].ToString();
                List <user> admmins = await db.users.Where(m => m.stat == 1).ToListAsync();

                user us = Session["User" + currid] as user;
                foreach (user usr in admmins)
                {
                    messenger1 mes = new messenger1();
                    mes.status       = 1;
                    mes.message      = text;
                    mes.datetime     = DateTime.Now;
                    mes.from_user_id = us.id;
                    mes.to_user_id   = usr.id;
                    db.messenger1.Add(mes);
                }
                db.SaveChanges();
            }
            return(Redirect("/Profile/Index/" + currid));
        }
Beispiel #14
0
        public async Task <ActionResult> Index(Log log)
        {
            string       login    = log.login;
            string       password = log.password;
            passwordHash hash     = new passwordHash();
            List <user>  auth     = new List <user>();

            auth = (from item in context.users where item.login == login select item).ToList();
            if (auth.Count == 0 || hash.Validate(password, auth[0].password) == false)
            {
                if (auth[0] != null)
                {
                    int?counter = auth[0].try_count + 1;
                    var user    = new user {
                        id = auth[0].id, try_count = counter
                    };
                    using (var db = new socialEntities())
                    {
                        db.users.Attach(user);
                        db.Entry(user).Property(x => x.try_count).IsModified = true;
                        db.SaveChanges();
                    }
                }
                if (auth[0].block_time < DateTime.Now)
                {
                    if (auth[0] != null)
                    {
                        var user = new user {
                            id = auth[0].id, try_count = 0
                        };
                        using (var db = new socialEntities())
                        {
                            db.users.Attach(user);
                            db.Entry(user).Property(x => x.try_count).IsModified = true;
                            db.SaveChanges();
                        }
                    }
                }
                if (auth[0].is_blocked == 1)
                {
                    auth[0].block_time = DateTime.Now.AddMinutes(30);
                    TimeSpan?time = auth[0].block_time - DateTime.Now;
                    ViewBag.error = string.Format("Administratin block your account");
                    return(View());
                }
                if (auth[0].try_count > 3)
                {
                    auth[0].block_time = DateTime.Now.AddMinutes(30);
                    TimeSpan?time = auth[0].block_time - DateTime.Now;
                    ViewBag.error = string.Format("too many unauthorized attempts your accont has blocked in {0} minutes", time);
                    return(View());
                }
                ViewBag.error = "please enter correct login or password";
                return(View());
            }
            else if (auth[0].ConfirmedEmail == "false")
            {
                ViewBag.error = "we send confirmation message to your Email please confirm it";
                return(View());
            }
            else
            {
                if (auth[0].stat == 1)
                {
                    int iD = auth[0].id;
                    Session["User" + iD.ToString()] = auth[0];
                    HttpCookie userId = new HttpCookie("id");
                    userId.Value   = iD.ToString();
                    userId.Expires = DateTime.Now.AddHours(2);
                    HttpContext.Response.SetCookie(userId);
                    TempData["id"] = iD.ToString();
                    return(RedirectToAction("Index", "Admin"));
                }
                if (auth[0] != null)
                {
                    var user = new user {
                        id = auth[0].id, try_count = 0
                    };
                    using (var db = new socialEntities())
                    {
                        db.users.Attach(user);
                        db.Entry(user).Property(x => x.try_count).IsModified = true;
                        db.SaveChanges();
                    }
                    int iD = auth[0].id;
                    Session["User" + iD.ToString()] = auth[0];
                    HttpCookie userId = new HttpCookie("id");
                    userId.Value   = iD.ToString();
                    userId.Expires = DateTime.Now.AddHours(2);
                    HttpContext.Response.SetCookie(userId);
                    TempData["id"] = iD.ToString();
                    return(RedirectToAction("Index", "Profile"));
                }
                return(View());
            }
        }