Exemple #1
0
        public async Task <IActionResult> Edit(Guid id, [Bind("Id,PostId,PhotoId")] PostPhotos postPhotos)
        {
            if (id != postPhotos.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(postPhotos);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PostPhotosExists(postPhotos.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["PhotoId"] = new SelectList(_context.Photos, "Id", "Id", postPhotos.PhotoId);
            ViewData["PostId"]  = new SelectList(_context.Post, "Id", "Id", postPhotos.PostId);
            return(View(postPhotos));
        }
Exemple #2
0
        public bool PostUpdatePost(updatePost posts)
        {
            var user = (from i in db.posts
                        where i.ID == posts.ID
                        select i).FirstOrDefault();

            user.Description  = posts.Description;
            user.PostDateTime = posts.PostDateTime;
            db.SaveChanges();
            PostPhotos postPhotos1 = new PostPhotos();
            var        postPhotos  = (from i in db.PostPhoto
                                      where i.PostID == posts.ID
                                      select i).ToList();

            while (postPhotos.Count > 0)
            {
                db.PostPhoto.Remove(postPhotos[postPhotos.Count - 1]);
                postPhotos.RemoveAt(postPhotos.Count - 1);
                db.SaveChanges();
            }

            foreach (var item in posts.postPhotos)
            {
                postPhotos1.Image = item;
                postPhotos1.Posts = user;
                db.PostPhoto.Add(postPhotos1);
                db.SaveChanges();
            }
            return(true);
        }
Exemple #3
0
        public bool PostPos(Postc posts)
        {
            var user = (from i in db.Users
                        where i.UserName == posts.UserName
                        select i.Id).FirstOrDefault();

            Posts p = new Posts();

            p.Description  = posts.Description;
            p.UserID       = user;
            p.PostDateTime = posts.PostDateTime;
            db.posts.Add(p);
            db.SaveChanges();
            PostPhotos postPhotos = new PostPhotos();

            //Save to DB
            foreach (var item in posts.postPhotos)
            {
                postPhotos.Image = item;
                postPhotos.Posts = p;
                db.PostPhoto.Add(postPhotos);
                db.SaveChanges();
            }
            return(true);
        }
        public async Task <IActionResult> PutPostPhotos(Guid id, PostPhotos postPhotos)
        {
            if (id != postPhotos.Id)
            {
                return(BadRequest());
            }

            _context.Entry(postPhotos).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PostPhotosExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemple #5
0
        public async Task <IActionResult> Create([Bind("Id,PostId,PhotoId")] PostPhotos postPhotos)
        {
            if (ModelState.IsValid)
            {
                postPhotos.Id = Guid.NewGuid();
                _context.Add(postPhotos);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["PhotoId"] = new SelectList(_context.Photos, "Id", "Id", postPhotos.PhotoId);
            ViewData["PostId"]  = new SelectList(_context.Post, "Id", "Id", postPhotos.PostId);
            return(View(postPhotos));
        }
        public async Task <ActionResult <PostPhotos> > PostPostPhotos(PostPhotos postPhotos)
        {
            _context.PostPhotos.Add(postPhotos);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (PostPhotosExists(postPhotos.Id))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtAction("GetPostPhotos", new { id = postPhotos.Id }, postPhotos));
        }
        public ActionResult AddPost(string postText)
        {
            if(String.IsNullOrEmpty(postText)) return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            var user = GetUserModel();
            var post = new Post
            {
                UserId=user.Id,
                PostText = postText,
                PostDatePosted = DateTime.Now
               
            };
            try
            {
                //yeni post kaydedilip id'si alınıyo
                _db.Posts.Add(post);
                _db.SaveChanges();
                _db.UsersLastMoves.Add(new UsersLastMoves { MoveDate = DateTime.Now, UserId = user.Id, UsersLastMoveText =" bir gönderi paylaştı.", UsersMoveLink = "/users/index/" + post.UserId + "#post" + post.PostID });
            }
            catch (Exception ex)
            {
                return Json(new { success = false, error = true, message = ex.InnerException.ToString() });
            }
            var photo = new PostPhotos();
            var postPhotoList = new List<PostPhotos>();
            var resizer = new ImageResize();
            if (Request.Files.Count > 0)
            {
                
                HttpFileCollectionBase files = Request.Files;
                for (int i=0;i< files.Count;i++)
                {
                    if (files[i] != null && files[i].ContentLength > 0)
                    {
                        Image imgBig = resizer.RezizeImage(Image.FromStream(files[i].InputStream, true, true), 640, 640);
                        var fileName = Path.GetFileName(files[i].FileName);
                        var fileNameBig = fileName.Replace(".", "-big.");
                        var pathBig = Path.Combine(Server.MapPath("~/images/post-images"), fileNameBig);
                        var databasePathBig = "../../images/post-images/" + fileNameBig;
                        imgBig.Save(pathBig);
                        //bir gönderiye birden fazla resim eklenebiliniyor.
                        var postPhotoLocation = new PostPhotos()
                        {
                            PostID = post.PostID,
                            PostPhotosLocateBig = databasePathBig,
                        };
                        postPhotoList.Add(postPhotoLocation);
                    }
                }
            }

            try
            {
                    //gönderinin resimlerinin sunucuda ki yerleri kaydediliyor
                    _db.PostPhotos.AddRange(postPhotoList);

                    _db.SaveChanges();
                    return Json(new { success = true });
            }
            catch (Exception ex)
            {
                _db.Posts.Remove(post);
                _db.PostPhotos.Remove(photo);
                _db.SaveChanges();
                return Json(new { success = false,error =true,message =ex.InnerException.ToString() });
            }

        }