public ActionResult CreateComment(ViewPostViewModel inModel)
        {
            var post = _ctx.Post.Where(m => m.Id == inModel.Id).SingleOrDefault();
            var images = _ctx.Image.Where(i => i.Post.Id == post.Id).AsEnumerable();
            var user = _ctx.UserProfiles.Where(u => u.UserId == post.User.UserId).SingleOrDefault();
            var recipient = post.User;
            var recipientEmail = recipient.Email;
            var comments = _ctx.Comment.Where(c => c.PostId == post.Id).ToList<Comment>();

            //TODO
            //if (!ModelState.IsValid)
            //{
            //    return View(inModel);
            //}

            var comment = new Comment();

            comment.Recipient = recipient.UserName;
            comment.Author = HttpContext.User.Identity.Name;
            comment.Subject = inModel.Subject;
            comment.Body = inModel.Body;
            comment.EntryDate = DateTime.Now;
            comment.LandLord = post.LandLord;
            comment.PostId = post.Id;

            _repository.AddComment(comment);

            try
            {
                var bemail = new MailMessage(recipientEmail, user.Email, "Someone commented on your Tenant's Village post", comment.Author + " commented on your post for " + comment.LandLord + "." +
                    System.Environment.NewLine + "Here is " + comment.Author + "'s comment:  "  +  inModel.Body);
                var smtpServer = new SmtpClient();
                smtpServer.Send(bemail);

            }
            catch (Exception e)
            {
                ModelState.AddModelError("", "There was an error sending your message");
                return View("Error");
            }

            var outModel = new ViewPostViewModel
            {
                Id = post.Id,
                Title = post.Title,
                LandLord = post.LandLord,
                LLemail = post.LLemail,
                Post = post.Post,
                Rent = post.Rent,
                Deposit = post.Deposit,
                AmtKept = post.AmountKept,
                LeaseYear = post.LeaseYear,
                Images = images,
                User = user,
                Comments = comments

            };

            return RedirectToAction("ViewPost", "Search", outModel);
        }
Ejemplo n.º 2
0
        public ActionResult Index()
        {
            var pics = _ctx.Image.Where(m => m.IsDeleted == false && m.Post.IsDeleted == false && m.IsThumbnail == false).OrderByDescending(m => m.Id).Take(10).ToList<ImageModel>();
            var outModel = new ViewPostViewModel();

                outModel.Pic_0 = pics[0];
                outModel.Pic_1 = pics[1];
                outModel.Pic_2 = pics[2];
                outModel.Pic_3 = pics[3];
                outModel.Pic_4 = pics[4];
                outModel.Pic_5 = pics[5];
                outModel.Pic_6 = pics[6];
                outModel.Pic_7 = pics[7];
                outModel.Pic_8 = pics[8];
                outModel.Pic_9 = pics[9];

            return View(outModel);
        }
Ejemplo n.º 3
0
        public ActionResult ViewPost(int id)
        {
            var post = _ctx.Post.Where(p => p.Id == id).SingleOrDefault();
            var images = _ctx.Image.Where(i => i.Post.Id == id && i.IsDeleted == false && i.IsThumbnail == false).AsEnumerable();
            var user = _ctx.UserProfiles.Where(u => u.UserId == post.User.UserId).SingleOrDefault();
            var comments = _ctx.Comment.Where(m => m.PostId == post.Id).ToList<Comment>();

            if (post.IsDeleted == true)
            {
                return View("DeletedPostError");
            }
            var outModel = new ViewPostViewModel()
            {
                Id = post.Id,
                Title = post.Title,
                LandLord = post.LandLord,
                LLemail = post.LLemail,
                Post = post.Post,
                Rent = post.Rent,
                Street = post.Street,
                Deposit = post.Deposit,
                AmtKept = post.AmountKept,
                LeaseYear = post.LeaseYear,
                Images = images,
                User = user,
                Comments = comments,
                AptNumber = post.AptNumber,
                BuildingNumber = post.BuildingNumber,
                Rating = post.Rating,
                ZipCode = post.ZipCode,
                City = post.City

            };

            if (_ctx.UserBookmark.Where(m => m.User.UserId == user.UserId).Where(m => m.Post.Id == post.Id).Any())
            {
                outModel.IsBookmarked = true;
            }

            return View(outModel);
        }
        public ActionResult ViewSampleComment(int threadId)
        {
            var thread = _ctx.Comment.Where(m => m.Id == threadId).SingleOrDefault();
            var cModel = new CommentViewModel
            {
                Author = thread.Author,
                Body = thread.Body,
                EntryDate = thread.EntryDate,
                Subject = thread.Subject
            };

            var outModel = new ViewPostViewModel
            {
                ComViewModel = cModel
            };

            return PartialView("_ViewComment", outModel);
        }
Ejemplo n.º 5
0
        public ActionResult Sample()
        {
            var post = "These people were ok.  Maintainence was done pretty quickly. Snow removal was lacking at times, " +
                        "but overall the parking was clear.  Parking was expensive, $500 a year, and there was no visitor parking. " +
                       "These people definitey gouge tenants on parking.  At the end of the lease, only a portion of my deposit was returned. "+
                       "Money was kept for carpet cleaning and minor repairs.  I am not too happy about the amount of my deposit withheld, but I did not take "+
                       "pictures so it will be difficult to counter their claims.  I would recommend this unit and company if the person renting is prepared "+
                       "to takes pictures and stand their ground come deposit time.";

            var images = _ctx.Image.Where(m => m.Post.Id == 8).ToList<ImageModel>();

            var comments = _ctx.Comment.Where(m => m.PostId == 0).ToList<Comment>();

            var outModel = new ViewPostViewModel
            {
                Title = "Sample Post",
                LandLord = "Sample Management",
                LeaseYear = 2012,
                LLemail = "*****@*****.**",
                Post = post,
                Rent = 650,
                Deposit = 650,
                AmountKept = 400,
                IsDeleted = false,
                Id = 0,
                AptNumber = "1",
                Images = images,
                BuildingNumber = 419,
                Street = "Poplar Rd",
                UserName = "******",
                City = "Iowa City",
                ZipCode = 52246,
                Rating = 6.5,
                IsDeleteMode = false,
                Comments = comments

            };

            return View(outModel);
        }
Ejemplo n.º 6
0
        public ActionResult Delete(ViewPostViewModel inModel)
        {
            var post = _ctx.Post.Where(p => p.Id == inModel.Id).SingleOrDefault();
            var currentUserId = _ctx.UserProfiles.Where(m => m.UserName == HttpContext.User.Identity.Name).SingleOrDefault().UserId;

            if (post.User.UserId != currentUserId)
            {
                return View("Error");
            }

            if (post.User.UserName == inModel.UserName) {
                post.IsDeleted = true;
                 _ctx.SaveChanges();
                 return RedirectToAction("Manage", "Post", new { needStatusUpdate = true, statusMessage = 5 });
            }
            else
            {
                return View("Error", inModel);
            }
        }
Ejemplo n.º 7
0
        public ActionResult Delete(int? id)
        {
            var post = _ctx.Post.Where(p => p.Id == id).SingleOrDefault();
            var images = _ctx.Image.Where(m => m.Post.Id == post.Id).ToList<ImageModel>();
            //var user = _ctx.UserProfiles.Find(post.User.UserId);
            var currentUserId = _ctx.UserProfiles.Where(m => m.UserName == HttpContext.User.Identity.Name).SingleOrDefault().UserId;

            if (post.User.UserId != currentUserId)
            {
                return View("Error");
            }

            if (post.IsDeleted == true)
            {
                ModelState.AddModelError("", "This post has already been deleted");
                return View();
            }

            var outModel = new ViewPostViewModel
            {
                Title = post.Title,
                LandLord = post.LandLord,
                LeaseYear = post.LeaseYear,
                LLemail = post.LLemail,
                Post = post.Post,
                Rent = post.Rent,
                Deposit = post.Deposit,
                AmountKept = post.AmountKept,
                IsDeleted = post.IsDeleted,
                Id = post.Id,
                AptNumber = post.AptNumber,
                Images = images,
                BuildingNumber = post.BuildingNumber,
                Street = post.Street,
                UserName = post.User.UserName,
                City = post.City,
                ZipCode = post.ZipCode,
                Rating = post.Rating,
                IsDeleteMode = true,

            };

            return View("DeleteConfirmation", outModel);
        }