public async Task <IHttpActionResult> PostHuntedAnimalPoints(HuntedAnimal huntedAnimal)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }



            var animalList = db.Animals.Where(a => a.AnimalId == huntedAnimal.Animal.AnimalId).ToList();

            animal = animalList[0];
            var hunterlist = db.Hunters.Where(h => h.HunterId == 1).ToList();

            hunter = hunterlist[0];

            huntedAnimal.Hunter = hunter;
            huntedAnimal.Animal = animal;



            db.HuntedAnimals.Add(huntedAnimal);
            await db.SaveChangesAsync();

            return(CreatedAtRoute("DefaultApi", new { id = huntedAnimal.HuntedAnimalId }, huntedAnimal));
        }
        public async Task <IHttpActionResult> PutHuntedAnimal(int id, HuntedAnimal huntedAnimal)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != huntedAnimal.HuntedAnimalId)
            {
                return(BadRequest());
            }

            db.Entry(huntedAnimal).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!HuntedAnimalExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        /// <summary>
        /// Selecteds the animal asynchronous.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="SelectionChangedEventArgs"/> instance containing the event data.</param>
        public async void SelectedAnimalAsync(object sender, SelectionChangedEventArgs e)
        {
            //Den her begynte bare å slutte å fungere og fikk en rar feilmelding som sa det var feil med assembly. Derfor try catch her.
            try
            {
                Animal = (Animal)e.AddedItems[0];
            }

            catch (Exception ex)
            {
                await Task.Run(() => ReportError.ErrorAsync(ex.Message));
            }

            //convert the Huntedanimal to child or parent
            if (Animal.IsPointsAnimal)
            {
                var serializedParent = JsonConvert.SerializeObject(HuntedAnimal);
                HuntedAnimalPoints c = JsonConvert.DeserializeObject <HuntedAnimalPoints>(serializedParent);
                HuntedAnimal = c;
                Visible      = true;
            }

            else
            {
                var          serializedParent = JsonConvert.SerializeObject(HuntedAnimal);
                HuntedAnimal c = JsonConvert.DeserializeObject <HuntedAnimal>(serializedParent);
                HuntedAnimal = c;
                Visible      = false;
            }
        }
        public async Task <IHttpActionResult> GetHuntedAnimal(int id)
        {
            HuntedAnimal huntedAnimal = await db.HuntedAnimals.FindAsync(id);

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

            return(Ok(huntedAnimal));
        }
Beispiel #5
0
        /// <summary>
        /// Gets the hunted animal weight.
        /// </summary>
        /// <param name="huntedAnimal">The hunted animal.</param>
        /// <returns></returns>
        private int GetHuntedAnimalWeight(HuntedAnimal huntedAnimal)
        {
            try
            {
                return(Int32.Parse(huntedAnimal.Weight));
            }

            catch
            {
                return(0);
            }
        }
Beispiel #6
0
        /// <summary>
        /// Gets the hunted animal bullet count.
        /// </summary>
        /// <param name="huntedAnimal">The hunted animal.</param>
        /// <returns></returns>
        private int GetHuntedAnimalBulletCount(HuntedAnimal huntedAnimal)
        {
            try
            {
                return(Int32.Parse(huntedAnimal.BulletCount));
            }

            catch
            {
                return(0);
            }
        }
        public async Task <IHttpActionResult> PostHuntedAnimal(HuntedAnimal huntedAnimal)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.HuntedAnimals.Add(huntedAnimal);
            await db.SaveChangesAsync();

            return(CreatedAtRoute("DefaultApi", new { id = huntedAnimal.HuntedAnimalId }, huntedAnimal));
        }
        public async Task <IHttpActionResult> DeleteHuntedAnimal(int id)
        {
            HuntedAnimal huntedAnimal = await db.HuntedAnimals.FindAsync(id);

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

            db.HuntedAnimals.Remove(huntedAnimal);
            await db.SaveChangesAsync();

            return(Ok(huntedAnimal));
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="CreateHuntedAnimalPageViewModel"/> class.
        /// Constructor
        /// </summary>
        public CreateHuntedAnimalPageViewModel()
        {
            //User can use GUI
            Visible = true;
            Hit     = true;
            Error   = true;
            //gets the date for today
            Date = DateTime.Today;

            //Make a new instance of HuntedAnimal
            HuntedAnimal = new HuntedAnimal("http://localhost:61604/api/Image?filename=DummyPicture.png");

            //Create a new Bitmap
            ImageSource = new BitmapImage(new Uri(imageUrl));

            StartAsync();
        }
Beispiel #10
0
    public int hunt(HuntedAnimal _target)
    {
        int dist        = Map.distance(_target.Pos, Pos);
        int rolledValue = SceneHandler.rollDice(diceValue);

        HasActionOutstanding = false;

        Debug.Log(rolledValue + "--" + dist);

        //Todo: MapTiles distance problem. get Distance
        if (rolledValue >= dist)
        {
            Debug.Log(meepleName + " hits " + _target.meepleName + " (distance: " + dist + " tiles) with a " + rolledValue);
            _target.Alive = false;
            return(_target.food);
        }

        Debug.Log(meepleName + "misses " + _target.meepleName + " (distance: " + dist + " tiles) with a " + rolledValue);
        return(0);
    }
        /// <summary>
        /// Creates the object asynchronous.
        /// </summary>
        public async void CreateObjectAsync()
        {
            //set text to nothing
            Text = "";

            Hit         = false;
            RingVisible = true;
            try
            {
                //Wait for GPS location
                var position = await Task.WhenAll(GetPositionAsync());

                var lat = position[0].Coordinate.Point.Position.Latitude;
                var lon = position[0].Coordinate.Point.Position.Longitude;

                //Set the latitude and longitude on HuntedAnimal object
                HuntedAnimal.Latitude  = lat;
                HuntedAnimal.Longitude = lon;
            }

            catch (Exception ex)
            {
                //if users device dosent support location it will be sat to Oslo
                //Default Oslo
                HuntedAnimal.Latitude  = 59.9;
                HuntedAnimal.Longitude = 10.75;
                await Task.Run(() => ReportError.ErrorAsync(ex.Message));
            }

            finally
            {
                HuntedAnimal.DateTime = Date.ToString("MM/dd/yyyy");

                try
                {
                    // check if Huntedanimal have points or not.
                    if (HuntedAnimal.GetType().Name == "HuntedAnimalPoints")
                    {
                        HuntedAnimal = await ApiCall.Post <HuntedAnimalPoints>("HuntedAnimalsPoints/", HuntedAnimal);
                    }
                    else
                    {
                        HuntedAnimal = await ApiCall.Post <HuntedAnimal>("HuntedAnimals/", HuntedAnimal);
                    }

                    // If user use own picture, post new picture.
                    if (HuntedAnimal.ImageUrl != "http://localhost:61604/api/Image?filename=DummyPicture.png")
                    {
                        HuntedAnimal.ImageUrl = path + HuntedAnimal.HuntedAnimalId.ToString() + ".jpg";
                        await ApiCall.Update(uri, HuntedAnimal);

                        await Task.Run(() => PostImageAsync());
                    }
                    Hit         = true;
                    RingVisible = false;

                    //navigate back to Home
                    NavigationService.Navigate(typeof(Views.HunterPage), HuntedAnimal);
                }

                //report error
                catch (Exception ex)
                {
                    await Task.Run(() => ReportError.ErrorAsync(ex.Message));

                    Text = "Det skjedde noe feil";
                }
            }
        }