public async Task <ActionResult> AddTestLandLordsFinal()
 {
     if (!IsAdminUser())
     {
         return(RedirectToAction("Unauthorized", "LandLords"));
     }
     try
     {
         var landlordnumber = db.LandLords.Count();
         if (landlordnumber == 0)
         {
             landlordnumber = 1;
         }
         for (int i = landlordnumber; i <= 100; i++)
         {
             var      landlordname = "LandLord" + i;
             LandLord landlord     = new LandLord();
             landlord.FullName            = landlordname;
             landlord.City                = "Cleveland";
             landlord.IndividualOrCompany = IndividualOrCompany.Individual;
             landlord.Description         =
                 "This is just a test landlord! Here is some information about this landlord. What a great/terrible landlord this landlord is! Yay!";
             landlord.PhoneNumber = "1231231234";
             landlord.State       = States.OH;
             landlord.IsApproved  = true;
             landlord.ZipCode     = "44145";
             var gls     = new GoogleLocationService();
             var latlong = gls.GetLatLongFromAddress(landlord.City + " " + landlord.ZipCode);
             landlord.Latitude  = latlong.Latitude;
             landlord.Longitude = latlong.Longitude;
             db.LandLords.Add(landlord);
             List <Rating> ratings = new List <Rating>();
             for (int k = 1; i <= 10; i++)
             {
                 Rating rating = new Rating();
                 rating.RatingName        = "Rating" + k;
                 rating.LandLord          = landlord;
                 rating.ContactPhoneNumer = UnspecifiedYesNo.Yes;
                 rating.LandLordRating    = 2;
                 rating.LateFees          = UnspecifiedYesNo.Yes;
                 rating.IsApproved        = true;
                 rating.RatingDescription = landlord.FullName + " is a terrible landlord! I'd never recommend this guy!";
                 rating.RatingName        = "Terrible landlord";
                 RatingReply ratingreply = new RatingReply();
                 ratingreply.ReplyDescription = "Thanks for the review!";
                 ratingreply.Rating           = rating;
                 db.Ratings.Add(rating);
                 db.RatingReplies.Add(ratingreply);
             }
             await db.SaveChangesAsync();
         }
         ViewBag.Message = "Success! 100 landlords with 10 ratings were added.";
     }
     catch (SystemException ex)
     {
         ViewBag.Message = ex.Message;
     }
     return(View());
 }
Пример #2
0
        public async Task <ActionResult> ReplyToRating(RatingReplyViewModel vm)
        {
            if (vm.RatingReply.ReplyDescription != null && vm.RatingReply.ReplyDescription.Length <= 2000)
            {
                vm.RatingReply.Rating = vm.Rating;
                RatingReply rr = new RatingReply();
                rr.ReplyDescription = vm.RatingReply.ReplyDescription;
                db.RatingReplies.Add(rr);
                await db.SaveChangesAsync();

                return(RedirectToAction("Details", "LandLords", new { id = vm.Rating.LandLordId }));
            }
            ViewBag.Message = "Error. Please enter a valid description.";
            return(View(vm));
        }
        public async Task <ActionResult> ApproveRatingReply(int?id)
        {
            if (!IsAdminUser())
            {
                return(RedirectToAction("Unauthorized", "LandLords"));
            }
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            RatingReply ratingreply = await db.RatingReplies.FindAsync(id);

            if (ratingreply == null || !IsAdminUser() || ratingreply.IsApproved)
            {
                return(HttpNotFound());
            }
            return(View(ratingreply));
        }
        public async Task <ActionResult> ApproveRatingReplyFinal(int?id)
        {
            if (!IsAdminUser())
            {
                return(RedirectToAction("Unauthorized", "LandLords"));
            }
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            RatingReply ratingreply = await db.RatingReplies.FindAsync(id);

            if (ratingreply == null || !IsAdminUser() || ratingreply.IsApproved)
            {
                return(HttpNotFound());
            }
            ratingreply.IsApproved      = true;
            ratingreply.Rating          = db.Ratings.FirstOrDefault(u => u.RatingReply.RatingReplyId == id);
            db.Entry(ratingreply).State = EntityState.Modified;
            try
            {
                await db.SaveChangesAsync();

                ViewBag.Message = "The Rating Reply for " + ratingreply.Rating.LandLord.FullName +
                                  " was approved and is live.";
                return(RedirectToAction("PendingRatingReplies"));
            }
            catch (DbEntityValidationException e)
            {
                foreach (var eve in e.EntityValidationErrors)
                {
                    Console.WriteLine(eve);
                }
                ViewBag.Message = "There was an error approving this rating reply: " + e.Message;
                return(RedirectToAction("PendingRatingReplies"));
            }
        }