Example #1
0
 public ActionResult Minify(String url)
 {
     using (var db = new bitContext())
     {
         BitUrl nUrl = new BitUrl()
         {
             appendDate = DateTime.Now,
             author     = db.Users.Find(Session.currentUserID()),
             longUrl    = url.Trim()
         };
         db.Urls.Add(nUrl);
         db.SaveChanges();
         return(PartialView("~/Views/Home/_UrlResult.cshtml", nUrl));
     }
 }
Example #2
0
        public ActionResult Click(string urlId)
        {
            using (var db = new bitContext())
            {
                long   id = MvcApplication.Minificator.Maxify(urlId);
                BitUrl bu = db.Urls.Find(id);
                if (bu != null)
                {
                    bu.clicks++;
                    db.SaveChanges();
                    return(new RedirectResult(bu.longUrl));
                }
            }

            return(RedirectToAction("Notfound"));
        }
Example #3
0
 public ActionResult Remove(int id)
 {
     using (var db = new bitContext())
     {
         var me = db.Users.Find(Session.currentUserID());
         if (me != null)
         {
             var u = me.urls.Where(x => x.id == id).FirstOrDefault();
             if (u != null)
             {
                 db.Urls.Remove(u);
                 db.SaveChanges();
             }
         }
     }
     return(new EmptyResult());
 }
Example #4
0
        protected void Session_Start()
        {
            /*  Пытаемся определить через Cookies пользвоателя,
             *  или создать/запомнить его, когда он заходит в первый раз */

            var cookies = Request.Cookies[COOKIE_NAME];

            using (var db = new bitContext())
            {
                User currUser = null;
                if (cookies != null)
                {
                    currUser = db.Users.Where(x => x.guid == cookies.Value).FirstOrDefault();
                }

                if (currUser == null)
                {
                    currUser = new User()
                    {
                        guid = Guid.NewGuid().ToString()
                    };
                    db.Users.Add(currUser);
                    db.SaveChanges();

                    cookies         = new HttpCookie(COOKIE_NAME, currUser.guid);
                    cookies.Expires = DateTime.Now.AddYears(1);
                }
                else
                {
                    cookies.Expires = DateTime.Now.AddYears(1);
                }

                Session[SS_USER_ID] = currUser.id;
                Response.Cookies.Add(cookies);
            }
        }