コード例 #1
0
        public ActionResult PublicPhoto()
        {
            classActive("publicActive");
            friendsDal     fd       = new friendsDal();
            string         username = Session["CurrentUsername"].ToString();
            List <Friends> curr     = (from x in fd.FriendsLst
                                       where (x.username.Equals(username)) || (x.friendUsername.Equals(username))
                                       select x).ToList <Friends>();
            List <string> friendsUserName = new List <string>();

            friendsUserName.Add(username);
            foreach (var friend in curr)
            {
                if (friend.username.Equals(username))
                {
                    friendsUserName.Add(friend.friendUsername);
                }
                else
                {
                    friendsUserName.Add(friend.username);
                }
            }
            PublicMomentPhotoView    pmpv   = new PublicMomentPhotoView();
            publicMomentPhotoDal     pmpd   = new publicMomentPhotoDal();
            List <publicMomentPhoto> photos = (from x in pmpd.momentPhotoLst
                                               where   friendsUserName.Any(item => item.Equals(x.username))
                                               select x).ToList <publicMomentPhoto>();

            pmpv.publicMomentphotos = photos;
            pmpv.photo = "photo";
            return(View(pmpv));
        }
コード例 #2
0
        public ActionResult AddPublicPhoto(IEnumerable <HttpPostedFileBase>
                                           imageModel)
        {
            byte[] data;
            using (Stream inputStram = Request.Files[0].InputStream)
            {
                MemoryStream memorystram = inputStram as MemoryStream;
                if (memorystram == null)
                {
                    memorystram = new MemoryStream();
                    inputStram.CopyTo(memorystram);
                }
                publicMomentPhotoDal mpd1 = new publicMomentPhotoDal();
                publicMomentPhoto    mp   = new publicMomentPhoto();
                data        = memorystram.ToArray();
                mp.photo    = data;
                mp.username = Session["CurrentUsername"].ToString();
                mpd1.momentPhotoLst.Add(mp);
                mpd1.SaveChanges();
                ViewData["photo"] = "Photo Added";
            }
            friendsDal     fd       = new friendsDal();
            string         username = Session["CurrentUsername"].ToString();
            List <Friends> curr     = (from x in fd.FriendsLst
                                       where (x.username.Equals(username)) || (x.friendUsername.Equals(username))
                                       select x).ToList <Friends>();
            List <string> friendsUserName = new List <string>();

            friendsUserName.Add(username);
            foreach (var friend in curr)
            {
                if (friend.username.Equals(username))
                {
                    friendsUserName.Add(friend.friendUsername);
                }
                else
                {
                    friendsUserName.Add(friend.username);
                }
            }
            PublicMomentPhotoView    pmpv   = new PublicMomentPhotoView();
            publicMomentPhotoDal     pmpd   = new publicMomentPhotoDal();
            List <publicMomentPhoto> photos = (from x in pmpd.momentPhotoLst
                                               where friendsUserName.Any(item => item.Equals(x.username))
                                               select x).ToList <publicMomentPhoto>();

            pmpv.publicMomentphotos = photos;
            pmpv.photo = "photo";
            return(View("PublicPhoto", pmpv));
        }
コード例 #3
0
        /*
         * public ActionResult UserMoments()
         * {
         *  users user = UserController.user;
         *  userMomentDal uMDal = new userMomentDal();
         *  List<userMoments> myMoments = (from x in uMDal.userMomentLST
         *                                 where x.username == user.username
         *                                 select x).ToList<userMoments>();
         *  momentsDal mDal = new momentsDal();
         *  List<moments> allMoments = (from x in mDal.momentsLst
         *                              select x).ToList<moments>();
         *  List<MomentsViewModel> user_momentsTOView = new List<MomentsViewModel>();
         *  List<moments> tmp = new List<moments>();
         *  foreach(userMoments u in myMoments)
         *  {
         *      MomentsViewModel model = new MomentsViewModel();
         *      model.moment = (from x in mDal.momentsLst
         *                      where u.mid == x.mid
         *                      select x).ToList<moments>()[0];
         *      model.mLst = (from x in uMDal.userMomentLST
         *                    where u.mid == x.mid
         *                    select x).ToList<userMoments>();
         *      user_momentsTOView.Add(model);
         *  }
         *  return View("UserMoments", user_momentsTOView);
         * }
         *
         * public ActionResult searchMoment()
         * {
         *
         *  string text = Request.Form["searchText"];
         *  momentsDal mDal = new momentsDal();
         *  List<moments> result = (from x in mDal.momentsLst
         *                      where x.mName.StartsWith(text)
         *                      select x).ToList<moments>();
         *  return View(result);
         *
         *
         * }*/
        public ActionResult deletePublicPhoto()
        {
            int postcode             = int.Parse(Request.Form["imgCode"].ToString());
            publicMomentPhotoDal dal = new publicMomentPhotoDal();

            dal.momentPhotoLst.RemoveRange(dal.momentPhotoLst.Where(x => x.postcode == postcode));
            try
            {
                dal.SaveChanges();
            }
            catch (Exception e)
            {
                ViewData["ErrorDeletePhoto"] = "Error occured while deleting the photo";
            }
            return(RedirectToAction("PublicPhoto", "Moment"));
        }