public JsonResult Login(string un, string pw) { Models.User user = null; if (Membership.ValidateUser(un, pw)) { FormsAuthentication.SetAuthCookie(un, true); Models.YoyoEntities db = new Models.YoyoEntities(); user = db.Users.Where(x => x.UserName.Equals(un,StringComparison.OrdinalIgnoreCase)).FirstOrDefault(); HttpCookie c = new HttpCookie("userId"); c.Expires = DateTime.Now.AddDays(60); c.Value = user.UserId.ToString(); Response.Cookies.Add(c); } object data = null; if (user == null) data = new { result = false }; else { if (user.Picture == null) user.Picture = new Models.Picture { Link = "profile.jpg" }; data = new { result = true, username = user.UserName, videoCount = user.Videos.Count, pictureLink = user.Picture.Link }; } return Json(data); //return RedirectToAction("Index"); }
public JsonResult GetVideo(int id) { Models.YoyoEntities db = new Models.YoyoEntities(); var video = db.Videos.Where(x => x.Id == id).FirstOrDefault(); return Json(new { url = video.Link, header = video.Name, description = video.Description,rating=video.Ratings.Count }); }
// // GET: /Home/ public ActionResult Index() { YoYo.Models.YoyoEntities db = new Models.YoyoEntities(); return View(db.Videos.ToList()); }
public ActionResult Upload(string name, string description, HttpPostedFileBase video) { Models.Video v = new Models.Video(); v.Date = DateTime.Now; v.Name = name; v.Description = description; v.Link = Guid.NewGuid().ToString().Replace("-", ""); v.UserId = new Guid(Membership.GetUser().ProviderUserKey.ToString()); string ext = Path.GetExtension(video.FileName).ToLower(); video.SaveAs(Server.MapPath("~/Videos/"+v.Link+ext)); Models.YoyoEntities db = new Models.YoyoEntities(); db.Videos.Add(v); db.SaveChanges(); Microsoft.Expression.Encoder.AudioVideoFile audiovideo = new Microsoft.Expression.Encoder.AudioVideoFile(Server.MapPath("~/Videos/" + v.Link + ext)); TimeSpan dur = audiovideo.Duration; int second = 1; int step = dur.Seconds / 5; for (int i = 1; i <= 5; i++) { int sc = second; int h = second / 3600; sc = sc - h * 3600; int m = sc / 60; sc = sc - m * 60; int s = sc; Bitmap bmp = audiovideo.GetThumbnail(new TimeSpan(h,m,s), new System.Drawing.Size(800, 600)); bmp.Save(Server.MapPath("~/VideosPictures/" + v.Link+"_"+i + ".png"), ImageFormat.Png); second += step; } return RedirectToAction("Index"); }
public ActionResult SignUp(string username, string password, string mail, HttpPostedFileBase picture) { MembershipUser user = Membership.CreateUser(username, password, mail); if (picture != null) { Models.Picture p = new Models.Picture(); p.Id = new Guid(user.ProviderUserKey.ToString()); p.Link = Guid.NewGuid().ToString().Replace("-", ""); string ext = Path.GetExtension(picture.FileName); p.Link += ext; picture.SaveAs(Server.MapPath("~/ProfilePictures/" + p.Link)); Models.YoyoEntities db = new Models.YoyoEntities(); db.Pictures.Add(p); db.SaveChanges(); } FormsAuthentication.SetAuthCookie(username, true); return RedirectToAction("Index"); }