Пример #1
0
        public HttpResponseMessage <Earthwatcher> GetByName(string name, HttpRequestMessage <string> request)
        {
            if (!string.IsNullOrEmpty(name))
            {
                var earthwatcher = earthwatcherRepository.GetEarthwatcher(name, true);
                if (earthwatcher == null)
                {
                    var response = new HttpResponseMessage <Earthwatcher>(HttpStatusCode.NotFound);
                    return(response);
                }

                //Si no tiene una parcela asignada, se le asigna una
                if (earthwatcher.Lands.Count == 0)
                {
                    // assign land
                    var  newLand    = earthwatcherRepository.AssignLandToEarthwatcher(earthwatcher.Id, string.Empty);
                    Land newLandObj = null;

                    if (newLand == null) //Si la region esta completa le asigno la land del tutor
                    {
                        newLandObj = landRepository.GetTutorLand(earthwatcher.PlayingRegion);
                    }
                    if (newLandObj == null) //Si no esta completa la region
                    {
                        newLandObj = landRepository.GetLandByGeoHexKey(newLand.GeohexKey);
                    }
                    //Comunico a los usuarios conectados si es que la nueva land es de un usuario existente
                    NotificateUsers(newLand, earthwatcher.Id);

                    earthwatcher.Lands.Add(newLandObj);
                    return(new HttpResponseMessage <Earthwatcher>(earthwatcher)
                    {
                        StatusCode = HttpStatusCode.OK
                    });
                }

                //EarthwatcherLinks.AddLinks(earthwatcher, request);
                return(new HttpResponseMessage <Earthwatcher>(earthwatcher)
                {
                    StatusCode = HttpStatusCode.OK
                });
            }
            return(new HttpResponseMessage <Earthwatcher>(null)
            {
                StatusCode = HttpStatusCode.BadRequest
            });
        }
Пример #2
0
        public bool SetTutorLand(string geoHexCode)
        {
            var landDB = landRepository.GetLandByGeoHexKey(geoHexCode);

            if (landDB != null)
            {
                landRepository.UpdateTutorLand(landDB.Id, landDB.RegionId);
                return(true);
            }
            else
            {
                return(false);
            }
        }