Ejemplo 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();
            }
        }
Ejemplo n.º 2
0
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                var team = this.repo.GetById(Convert.ToInt32("TeamId"));
                team.TeamName = collection.Get("TeamName");

                var locationRepo = new LocationRepository();

                var city = collection.Get("City");
                var stateId = Convert.ToInt32(collection.Get("StateId"));

                var location = locationRepo.GetByCityStateId(city, stateId);

                if (null == location)
                {
                    location = new Location();
                    location.City = city;
                    location.StateId = stateId;
                }
                locationRepo.Save(location);

                team.LocationId = location.LocationId;

                this.repo.Add(team);

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
Ejemplo n.º 3
0
        private void FixupLocation(Location previousValue)
        {
            if (previousValue != null && previousValue.Teams.Contains(this))
            {
                previousValue.Teams.Remove(this);
            }

            if (Location != null)
            {
                if (!Location.Teams.Contains(this))
                {
                    Location.Teams.Add(this);
                }
                if (LocationId != Location.LocationId)
                {
                    LocationId = Location.LocationId;
                }
            }
        }