Esempio n. 1
0
        public ActionResult Create(HttpPostedFileBase file_upload, FormCollection collection)
        {
            ImagePaths photoPaths = null;
            ImageDimensions imgDims = null;
            ImagePaths thumbNailPaths = null;

            try
            {
                photoPaths = SaveUploadedFile(file_upload);
                imgDims = ImageHandler.GetImageDimensions(photoPaths.FilePath);

                //Save file
                var photo = new Photo();
                photo.PhotoUrl = photoPaths.SqlAddress;
                if (imgDims != null)
                {
                    photo.Width = imgDims.Width;
                    photo.Height = imgDims.Height;
                }
                var photoRepo = new PhotoRepository();
                photoRepo.Save(photo);

                var team = new Team {TeamName = collection.Get("TeamName")};

                //Save Location
                var locationRepo = new LocationRepository();
                var location = new Location();
                location.City = collection.Get("City");
                location.StateId = Convert.ToInt32(collection.Get("StateId"));
                locationRepo.Add(location);

                team.LocationId = location.LocationId;
                team.PhotoId = photo.PhotoId;

                this.repo.Add(team);

                return RedirectToAction("Index");
            }
            catch
            {
                ViewBag.States = this.GetStates();
                return View();
            }
        }
Esempio n. 2
0
        private void FixupPhoto(Photo previousValue)
        {
            if (previousValue != null && previousValue.Teams.Contains(this))
            {
                previousValue.Teams.Remove(this);
            }

            if (Photo != null)
            {
                if (!Photo.Teams.Contains(this))
                {
                    Photo.Teams.Add(this);
                }
                if (PhotoId != Photo.PhotoId)
                {
                    PhotoId = Photo.PhotoId;
                }
            }
            else if (!_settingFK)
            {
                PhotoId = null;
            }
        }