コード例 #1
0
ファイル: DashController.cs プロジェクト: TobbyJay/Spotahubb
        public IActionResult AddListings(OwnerHubsViewModel model)
        {
            var    user           = _ownerService.GetOwnerByEmail(User.Identity.Name);
            string imagesFileName = ProcessUploadedFile(model);

            if (ModelState.IsValid)
            {
                Hubb newHub = new Hubb()
                {
                    HubName        = model.Hubb.HubName,
                    Keywords       = model.Hubb.Keywords,
                    Address        = model.Hubb.Address,
                    City           = model.Hubb.City,
                    State          = model.Hubb.State,
                    ZipCode        = model.Hubb.ZipCode,
                    HubDescription = model.Hubb.HubDescription,
                    PhoneNumber    = model.Hubb.PhoneNumber,
                    Website        = model.Hubb.Website,
                    Email          = model.Hubb.Email,
                    FacebookLink   = model.Hubb.FacebookLink,
                    TwitterLink    = model.Hubb.TwitterLink,
                    HubImages      = imagesFileName,
                    Status         = HubStatus.Claimed,
                    OwnerId        = user.OwnerId
                };

                _hubDataStore.Post(newHub);


                return(RedirectToAction("listings", "dash"));
            }
            return(View());
        }
コード例 #2
0
ファイル: DashController.cs プロジェクト: TobbyJay/Spotahubb
        private string ProcessUploadedFile(OwnerHubsViewModel model)
        {
            string uniqueFileName = null;

            if (model.Image != null)
            {
                string uploadsFolder = Path.Combine(_webHostEnvironment.WebRootPath, "images");
                uniqueFileName = Guid.NewGuid().ToString() + "_" + model.Image.FileName;

                string filePath = Path.Combine(uploadsFolder, uniqueFileName);

                model.Image.CopyTo(new FileStream(filePath, FileMode.Create));
            }

            return(uniqueFileName);
        }