public ActionResult Feed() { var database = new InstagramDbContext(); ViewBag.currentUser = database.Users.Find(1); return(View(database.Photos.ToList())); }
public ActionResult UploadPhoto() { InstagramDbContext database = new InstagramDbContext(); var users = database.Users.ToList(); return(View(users)); }
public ActionResult PressLike(int userId, int photoId) { var database = new InstagramDbContext(); var user = database.Users.Find(userId); var photo = database.Photos.Find(photoId); var like = database.Likes.Where(x => x.User.Id == user.Id && x.Photo.Id == photo.Id).FirstOrDefault(); var Liked = database.Likes; if (like == null) { like = new Like(); like.Photo = photo; like.User = user; database.Likes.Add(like); database.SaveChanges(); } else { database.Likes.Remove(like); database.SaveChanges(); } return(RedirectToAction("feed")); }
public ActionResult GetTokenScript(int clientid) { var optionsBuilder = new DbContextOptionsBuilder <InstagramDbContext>(); optionsBuilder.UseSqlServer("Data Source=webs.bozell.com;Initial Catalog=Instagram;Persist Security Info=True;User ID=sa;Password=orajen1411!"); var db = new InstagramDbContext(optionsBuilder.Options); var token = db.Tokens.Include("Client").SingleOrDefault(x => x.Id == clientid); if (token.DateModified < DateTime.Now.AddDays(-1)) { using (var wb = new WebClient()) { var response = wb.DownloadString("https://graph.instagram.com/refresh_access_token?grant_type=ig_refresh_token&access_token=" + token.AccessToken); var json = Newtonsoft.Json.JsonConvert.DeserializeObject <InstagramResponse>(response); token.AccessToken = json.access_token; token.DateModified = DateTime.Now; db.SaveChanges(); } } return(Content("const InstagramToken = '" + token.AccessToken + "';")); }
public ActionResult Feed() { var database = new InstagramDbContext(); int userID = (int)System.Web.HttpContext.Current.Session["userID"]; //ViewBag.userID = userID; ViewBag.user = database.Users.Find(userID); return(View(database.Photos.OrderByDescending(p => p.Date).ToList())); }
public string SavePhoto(string photo, int userId, string caption) { InstagramDbContext database = new InstagramDbContext(); Photo temp_photo = new Photo(); temp_photo.Picture = photo; temp_photo.Caption = caption; temp_photo.PhotoUser = database.Users.Find(userId); temp_photo.Date = DateTime.Now; database.Photos.Add(temp_photo); database.SaveChanges(); return("I worked?"); }
public ActionResult SavePhoto(HttpPostedFileBase photo, int userId, string caption) { InstagramDbContext database = new InstagramDbContext(); Photo temp_photo = new Photo(); temp_photo.Picture = photo.FileName; temp_photo.PictureData = new byte[photo.ContentLength]; photo.InputStream.Read(temp_photo.PictureData, 0, photo.ContentLength); temp_photo.Caption = caption; temp_photo.PhotoUser = database.Users.Find(userId); temp_photo.Date = DateTime.Now; database.Photos.Add(temp_photo); database.SaveChanges(); return(RedirectToAction("Feed")); }
public ActionResult SavePhoto(HttpPostedFileBase photo, string caption) { InstagramDbContext database = new InstagramDbContext(); Photo temp_photo = new Photo(); int userID = (int)System.Web.HttpContext.Current.Session["userID"]; temp_photo.Picture = new byte[photo.ContentLength]; photo.InputStream.Read(temp_photo.Picture, 0, photo.ContentLength); temp_photo.Caption = caption; temp_photo.PhotoUser = database.Users.Find(userID); temp_photo.Date = DateTime.Now; database.Photos.Add(temp_photo); database.SaveChanges(); return(RedirectToAction("Feed")); }
public ActionResult GetImage(int id) { var database = new InstagramDbContext(); var photo = database.Photos.Find(id); using (var ms = new MemoryStream(photo.Picture)) { var image = System.Drawing.Image.FromStream(ms); var ratioX = (double)300 / image.Width; var ratioY = (double)300 / image.Height; var ratio = Math.Min(ratioX, ratioY); var width = (int)(image.Width * ratio); var height = (int)(image.Height * ratio); var newImage = new System.Drawing.Bitmap(width, height); System.Drawing.Graphics.FromImage(newImage).DrawImage(image, 0, 0, width, height); System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(newImage); System.Drawing.ImageConverter converter = new System.Drawing.ImageConverter(); photo.Picture = (byte[])converter.ConvertTo(bmp, typeof(byte[])); var stream = new MemoryStream(photo.Picture); var bitmap = new Bitmap(stream); var newstream = new MemoryStream(); bitmap.Save(newstream, ImageFormat.Jpeg); newstream.Position = 0; return(new FileStreamResult(newstream, "image/jpg")); // return "data:image/*;base64," + Convert.ToBase64String(photo.Picture); } }
public ActionResult GetImage(int id) { var database = new InstagramDbContext(); var photo = database.Photos.Find(id); var stream = new MemoryStream(photo.PictureData); var bitmap = new Bitmap(stream); for (int i = 0; i < bitmap.Height; i++) { for (int j = 0; j < bitmap.Width; j++) { var temp_pixel = bitmap.GetPixel(j, i); // int average = (temp_pixel.R + temp_pixel.B + temp_pixel.G) / 3; // bitmap.SetPixel(j, i, Color.FromArgb(temp_pixel.R / 2, temp_pixel.G, temp_pixel.B)); } } var newstream = new MemoryStream(); bitmap.Save(newstream, ImageFormat.Jpeg); newstream.Position = 0; return(new FileStreamResult(newstream, "image/jpg")); }
public ItemsService(InstagramDbContext db) { this.db = db; }
public RaitingService(InstagramDbContext ctx) { _ctx = ctx; }
public ReportService(InstagramDbContext ctx) { _ctx = ctx; }
public ActionResult Feed() { var database = new InstagramDbContext(); return(View(database.Photos.OrderByDescending(p => p.Date).ToList())); }
public ActionResult Feed() { var database = new InstagramDbContext(); return(View(database.Photos.ToList())); }
public FollowServise(InstagramDbContext context) { _context = context; }
public CommentService(InstagramDbContext ctx) { _ctx = ctx; }
public PostServices(InstagramDbContext ctx, IUser userService, IHttpContextAccessor httpCtxAcc) { _ctx = ctx; _userService = userService; _httpCtxAcc = httpCtxAcc; }