Esempio n. 1
0
        public HttpResponseMessage <Land> ReassignLand(Earthwatcher e, HttpRequestMessage <Earthwatcher> request)
        {
            if (e.Id != 0)
            {
                try
                {
                    var newLand = landRepository.ReassignLand(e.Id);

                    if (newLand != null)
                    {
                        Land newLandObj = landRepository.GetLandByGeoHexKey(newLand.GeohexKey);
                        if (newLandObj != null)
                        {
                            newLandObj.EarthwatcherId = e.Id;
                            NotificateUsers(newLand, e.Id);
                            return(new HttpResponseMessage <Land>(newLandObj)
                            {
                                StatusCode = HttpStatusCode.Created
                            });
                        }
                    }
                    else
                    {
                        Land newLandObj = landRepository.GetTutorLand(e.PlayingRegion);
                        return(new HttpResponseMessage <Land>(newLandObj)
                        {
                            StatusCode = HttpStatusCode.Created, ReasonPhrase = Labels.Labels.NoMoreLands
                        });
                    }
                }
                catch (Exception ex)
                {
                    logger.Error("Ocurrio una excepcion en el ReasignLand. Message: {0},  StackTrace:{1}", ex.Message, ex.StackTrace);
                    return(new HttpResponseMessage <Land>(null)
                    {
                        StatusCode = HttpStatusCode.Conflict, ReasonPhrase = ex.Message
                    });
                }
            }

            return(new HttpResponseMessage <Land>(null)
            {
                StatusCode = HttpStatusCode.BadRequest
            });
        }