Example #1
0
        public ActionResult ClaimLandLord(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            LandLord landlord = db.LandLords.Find(id);

            if (landlord == null)
            {
                return(HttpNotFound());
            }
            var user = GetCurrentUser();

            if (user.ClaimedLandLordId != 0)
            {
                return(RedirectToAction("AlreadyClaimed"));
            }
            if (landlord.IsClaimed)
            {
                return(RedirectToAction("LandLordAlreadyClaimed", new { id = landlord.LandLordId }));
            }


            ClaimLandLordViewModel vm = new ClaimLandLordViewModel();

            vm.LandLordName        = landlord.FullName;
            TempData["landlordid"] = id;
            return(View(vm));
        }
Example #2
0
        public async Task <ActionResult> ClaimLandLord(
            [Bind(
                 Include =
                     "Id,ClaimName,ClaimDescription,DocumentFilePath,IsPending,IsApproved,ApplicationUser_Id,LandLord_LandLordId"
                 )] ClaimLandLordViewModel vm, HttpPostedFileBase document)
        {
            if (Request.Files.Count > 0)
            {
                var file = Request.Files[0];
                vm.Document = file;
            }

            var landlordid = TempData["landlordid"];
            var landlord   = await db.LandLords.FindAsync(landlordid);

            if (landlord != null)
            {
                vm.LandLord = landlord;
            }

            //Manually changed to test all values, redirect to view if not valid. Was previously ModelState.IsValid but was broken and couldn't figure out why it wouldn't find the document.
            if (vm.Document != null && vm.ClaimName != null && vm.ClaimDescription != null && vm.LandLord != null)
            {
                ApplicationUser currentUser   = GetCurrentUser();
                var             landLordClaim = new LandLordClaim();
                var             docPath       = Path.Combine(Server.MapPath("~/uploads"), vm.Document.FileName);
                vm.Document.SaveAs(docPath);
                landLordClaim.DocumentFilePath = docPath;
                landLordClaim.ClaimName        = vm.ClaimName;
                landLordClaim.ClaimDescription = vm.ClaimDescription;
                landLordClaim.ApplicationUser  = currentUser;
                landLordClaim.LandLord         = vm.LandLord;
                db.LandLordClaims.Add(landLordClaim);
                await db.SaveChangesAsync();

                return(RedirectToAction("ClaimSubmitted"));
            }
            ViewBag.Message = "Error. Please fill out all values.";
            return(View(vm));
        }