Example #1
0
        /// <summary>
        /// Update gym, IF we find the ID of the gym being changed
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int UpdateGym(GymViewModel model)
        {
            int rowsAffected = 0;

            Gym entity = _dbContext.Gyms.Find(model.GymId);

            if (entity != null)
            {
                entity.GymName     = model.GymName;
                entity.GymPrice    = model.GymPrice;
                entity.GymAddress1 = model.GymAddress1;
                entity.GymAddress2 = model.GymAddress2;
                entity.GymUrl      = model.GymUrl;

                try
                {
                    rowsAffected = _dbContext.SaveChanges();
                }
                catch (Exception)
                {
                    throw;
                }
            }

            return(rowsAffected);
        }
Example #2
0
        public IActionResult EditGym(int id)
        {
            // Retrieve the gym from the database to be edited by the user.
            Gym gym = gymRepository.GetGym(id);

            if (gym != null)
            {
                GymViewModel model = new GymViewModel
                {
                    Id             = gym.Id,
                    GymName        = gym.GymName,
                    Email          = gym.Email,
                    AddressLineOne = gym.AddressLineOne,
                    AddressLineTwo = gym.AddressLineTwo,
                    Town           = gym.Town,
                    Postcode       = gym.Postcode,
                    Telephone      = gym.Telephone
                };

                return(View(model));
            }
            else
            {
                return(RedirectToAction(nameof(ListGyms)));
            }
        }
Example #3
0
        /// <summary>
        /// Create Gym, receives a model (new gym), and pushes into Gym, via db context
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int CreateGym(GymViewModel model)
        {
            int gymId = 0;

            Gym entity = new Gym
            {
                GymName     = model.GymName,
                GymPrice    = model.GymPrice,
                GymAddress1 = model.GymAddress1,
                GymAddress2 = model.GymAddress2,
                GymUrl      = model.GymUrl
            };

            //inside of gym table, add in information being passed down
            _dbContext.Gyms.Add(entity);

            try
            {
                //save changes, updates table and creates a gym id
                _dbContext.SaveChanges();

                //gym id is available via savechanges
                gymId = entity.GymId;
            }
            catch (Exception)
            {
                throw;
            }

            return(gymId);
        }
        // GET: Gyms/Delete/5
        public async Task <IActionResult> Delete(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var gym = await _unitOfWork.GymRepository.GetAsync(id);

            if (gym == null)
            {
                return(NotFound());
            }
            //var gymVm = _mapper.Map<Gym, GymViewModel>(gym);
            var gymVm = new GymViewModel();

            gymVm.City        = gym.City;
            gymVm.Country     = gym.Country;
            gymVm.Customers   = gym.Customers;
            gymVm.Description = gym.Description;
            gymVm.Email       = gym.Email;
            gymVm.Employees   = gym.Employees;
            gymVm.GymName     = gym.GymName;
            gymVm.Email       = gym.Email;
            gymVm.Employees   = gym.Employees;
            gymVm.GymName     = gym.GymName;
            gymVm.PhoneNumber = gym.PhoneNumber;
            gymVm.PostalCode  = gym.PostalCode;
            gymVm.Street      = gym.Street;
            gymVm.Website     = gym.Website;

            return(View(gymVm));
        }
Example #5
0
        public ActionResult Add(GymViewModel gym)
        {
            try
            {
                if (string.IsNullOrEmpty(gym.Name) ||
                    string.IsNullOrEmpty(gym.Description) ||
                    string.IsNullOrEmpty(gym.Website) ||
                    string.IsNullOrEmpty(gym.Address))

                {
                    ViewBag.InvalidForm = true;
                    return(View());
                }
                else
                {
                    gymDbContext.Add(new Gym()
                    {
                        Address     = gym.Address,
                        Description = gym.Description,
                        IsActive    = true,
                        Name        = gym.Name,
                        Website     = gym.Website
                    });
                    gymDbContext.SaveChanges();

                    return(Redirect("/"));
                }
            }
            catch
            {
                return(View());
            }
        }
        // GET: Gyms/Edit/5
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var gym = await _unitOfWork.GymRepository.GetBy(g => g.GymId == id, g => g.Employees, g => g.Customers);

            if (gym == null)
            {
                return(NotFound());
            }
            ViewBag.Countries = new SelectList(Country.GetCountries(), "ID", "Name");
            //var gymVm = _mapper.Map<Gym, GymViewModel>(gym);
            var gymVm = new GymViewModel();

            gymVm.City        = gym.City;
            gymVm.Country     = gym.Country;
            gymVm.Customers   = gym.Customers;
            gymVm.Description = gym.Description;
            gymVm.Email       = gym.Email;
            gymVm.Employees   = gym.Employees;
            gymVm.GymName     = gym.GymName;
            gymVm.Email       = gym.Email;
            gymVm.Employees   = gym.Employees;
            gymVm.GymName     = gym.GymName;
            gymVm.PhoneNumber = gym.PhoneNumber;
            gymVm.PostalCode  = gym.PostalCode;
            gymVm.Street      = gym.Street;
            gymVm.Website     = gym.Website;
            gymVm.GymId       = gym.GymId;

            return(View(gymVm));
        }
Example #7
0
        public GymListView()
        {
            InitializeComponent();
            viewModel = new GymViewModel(this);
            NavigationPage.SetHasNavigationBar(this, false);

            BindingContext = viewModel;

            keyboardOpen = false;
            sliderOverlay.OnSizeChange += (sender, e) =>
            {
                if (e.Old > e.New)
                {
                    HideKeyboard();
                }
            };

            sliderOverlay.OnGymSelected += (sender, e) =>
            {
                var moveToPos = new Xamarin.Forms.Maps.Position(e.Location.Lat, e.Location.Lng);
                map.MoveToRegion(MapSpan.FromCenterAndRadius(moveToPos, defaultDistance));
                HideKeyboard();
                ovelayController.Minimize(sliderOverlay);
            };

            sliderOverlay.OnSearchFocus += (sender, e) =>
            {
                keyboardOpen = true;
                ovelayController.MaximizeOverlay(sliderOverlay);
            };
            SetupLocation();
        }
        public async Task <IActionResult> Edit(int id, [Bind("GymId,GymName,Description,Website,Email,Country,City,PostalCode,Street,PhoneNumber,AvatarImage")] GymViewModel model)
        {
            //var gym = _mapper.Map<GymViewModel, Gym>(model);
            var gym = _unitOfWork.GymRepository.Get(model.GymId);


            if (id != gym.GymId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                gym.City        = model.City;
                gym.Country     = model.Country;
                gym.Customers   = model.Customers;
                gym.Description = model.Description;
                gym.Email       = model.Email;
                gym.Employees   = model.Employees;
                gym.GymName     = model.GymName;
                gym.Email       = model.Email;
                gym.Employees   = model.Employees;
                gym.GymName     = model.GymName;
                gym.PhoneNumber = model.PhoneNumber;
                gym.PostalCode  = model.PostalCode;
                gym.Street      = model.Street;
                gym.Website     = model.Website;
                try
                {
                    if (model.AvatarImage != null)
                    {
                        using (var memoryStream = new MemoryStream())
                        {
                            await model.AvatarImage.CopyToAsync(memoryStream);

                            gym.AvatarImage = memoryStream.ToArray();
                        }
                    }
                    _unitOfWork.GymRepository.Update(gym);
                    await _unitOfWork.GymRepository.SaveAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!_unitOfWork.GymRepository.Exists(gym.GymId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewBag.Countries = new SelectList(Country.GetCountries(), "ID", "Name", gym.Country);
            var gymVm = _mapper.Map <Gym, GymViewModel>(gym);

            return(View(gymVm));
        }
Example #9
0
        public IActionResult Create(GymViewModel gymViewModel)
        {
            var admin = HttpContext.Session.GetObjectFromJson <User>("admin");

            if (admin == null)
            {
                return(RedirectToAction("Index", "Auth"));
            }
            if (ModelState.IsValid)
            {
                db.Gym.Add(
                    new Gym {
                    OwnerId = gymViewModel.OwnerId,
                    Title   = gymViewModel.Title
                }
                    );
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(gymViewModel));
        }
Example #10
0
        public IActionResult AddGym(GymViewModel model)
        {
            if (ModelState.IsValid)
            {
                Gym gym = new Gym
                {
                    GymName        = model.GymName,
                    Email          = model.Email,
                    AddressLineOne = model.AddressLineOne,
                    AddressLineTwo = model.AddressLineTwo,
                    Town           = model.Town,
                    Postcode       = model.Postcode,
                    Telephone      = model.Telephone
                };

                gymRepository.Add(gym);

                return(RedirectToAction(nameof(ListGyms)));
            }

            return(View(model));
        }
Example #11
0
        public IActionResult EditGym(GymViewModel model)
        {
            if (ModelState.IsValid)
            {
                Gym gym = gymRepository.GetGym(model.Id);
                gym.Id             = model.Id;
                gym.GymName        = model.GymName;
                gym.Email          = model.Email;
                gym.AddressLineOne = model.AddressLineOne;
                gym.AddressLineTwo = model.AddressLineTwo;
                gym.Town           = model.Town;
                gym.Postcode       = model.Postcode;
                gym.Telephone      = model.Telephone;

                gymRepository.Update(gym);

                return(RedirectToAction(nameof(ListGyms)));
            }
            else
            {
                ModelState.AddModelError(string.Empty, "Error in the form");
                return(View(model));
            }
        }
        public async Task <IActionResult> Create([Bind("GymId,GymName,Description,Website,Email,Country,City,PostalCode,Street,PhoneNumber,AvatarImage")] GymViewModel model)
        {
            var gym = _mapper.Map <GymViewModel, Gym>(model);

            if (ModelState.IsValid)
            {
                if (model.AvatarImage != null)
                {
                    using (var memoryStream = new MemoryStream())
                    {
                        await model.AvatarImage.CopyToAsync(memoryStream);

                        gym.AvatarImage = memoryStream.ToArray();
                    }
                }
                _unitOfWork.GymRepository.Add(gym);
                await _unitOfWork.GymRepository.SaveAsync();

                return(RedirectToAction(nameof(Index)));
            }
            var gymVm = _mapper.Map <Gym, GymViewModel>(gym);

            return(View(gymVm));
        }
Example #13
0
 public GymMarker(MainClientWindow window, GMapMarker marker, FortData item) : this(window, marker)
 {
     fort        = new GymViewModel(item);
     DataContext = fort;
 }