Ejemplo n.º 1
0
        public ActionResult Create(LandlordAddressViewModel theVM)
        {
            string   uniqueFileName = UploadedFile(theVM);
            Image    newImage       = new Image();
            Address  newAddress     = new Address();
            Landlord newLandlord    = new Landlord();
            var      userId         = this.User.FindFirstValue(ClaimTypes.NameIdentifier);

            newLandlord.IdentityUserId = userId;
            _repo.Image.CreateImage(newImage);
            _repo.Landlord.CreateLandlord(newLandlord);
            newLandlord.IdentityUserId = userId;
            newLandlord.FirstName      = theVM.FirstName;
            newLandlord.LastName       = theVM.LastName;
            newLandlord.CompanyName    = theVM.CompanyName;
            newLandlord.Email          = theVM.Email;
            newLandlord.PhoneNumber    = theVM.PhoneNumber;
            newLandlord.Address        = newAddress;
            newAddress.StreetAddress   = theVM.StreetAddress;
            newAddress.City            = theVM.City;
            newAddress.State           = theVM.State;
            newAddress.Zipcode         = int.Parse(theVM.ZipCode);
            newImage.ProfileImage      = uniqueFileName;
            newLandlord.ProfileImage   = uniqueFileName;
            _repo.Save();
            try
            {
                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(View());
            }
        }
Ejemplo n.º 2
0
        private string UploadedFile(LandlordAddressViewModel model)
        {
            string uniqueFileName = null;

            if (model.ProfileImage != null)
            {
                string uploadsFolder = Path.Combine(webHostEnvironment.WebRootPath, "images");
                uniqueFileName = Guid.NewGuid().ToString() + "_" + model.ProfileImage.FileName;
                string filePath = Path.Combine(uploadsFolder, uniqueFileName);
                using var fileStream = new FileStream(filePath, FileMode.Create);
                model.ProfileImage.CopyTo(fileStream);
            }
            return(uniqueFileName);
        }