Beispiel #1
0
        public IMobile CreateMobile(MobileSystem system, string name, string version)
        {
            var mobile   = new Mobile(system, name, version);
            var response = _mobileRepository.Add(mobile);

            StoreMobiles();
            return(response);
        }
Beispiel #2
0
        public async Task <Object> AddMobile(MobileModelView MobileFromView)
        {
            try
            {
                Mobile mobileToAdd = new Mobile();
                mobileToAdd = _mapper.Map <MobileModelView, Mobile>(MobileFromView);
                await _mobileRepo.Add(mobileToAdd);

                return(Ok(new { succuess = true, Data = "Mobile Record Bien Ajoutée" }));
            }
            catch (Exception e)
            {
                return(BadRequest(new
                                  { success = false, data = "il ya un erreur pendant l'ajout de record", exception = e }));
            }
        }
        public async Task <IActionResult> discoverLocation(int locationId, int userId)
        {
            if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            var user = await _repo.GetUser(userId);

            if (user == null)
            {
                return(NotFound());
            }

            var location = await _repo.GetLocation(locationId);

            if (location == null)
            {
                return(NotFound());
            }

            if (await _repo.UserLocationAlreadyExist(locationId, userId))
            {
                return(BadRequest("You have already discovered this location."));
            }

            var mobileUserLocation = new MobileUserLocation
            {
                LocationId   = locationId,
                MobileUserId = userId
            };

            _repo.Add(mobileUserLocation);

            if (await _repo.SaveAll())
            {
                return(Ok());
            }

            return(BadRequest("Failed to add location to user"));
        }