コード例 #1
0
 public virtual ActionResult Locate(EstablishmentForm model)
 {
     if (model != null)
     {
         var establishment = _queryProcessor.Execute(new EstablishmentByGuid(model.EntityId)
         {
             EagerLoad = new Expression<Func<Establishment, object>>[]
             {
                 e => e.Location,
             }
         });
         if (establishment != null)
         {
             var command = new UpdateEstablishment
             {
                 Id = establishment.RevisionId,
                 GoogleMapZoomLevel = model.Location.GoogleMapZoomLevel,
                 CenterLatitude = model.Location.CenterLatitude,
                 CenterLongitude = model.Location.CenterLongitude,
                 NorthLatitude = model.Location.BoundingBoxNortheastLatitude,
                 EastLongitude = model.Location.BoundingBoxNortheastLongitude,
                 SouthLatitude = model.Location.BoundingBoxSouthwestLatitude,
                 WestLongitude = model.Location.BoundingBoxSouthwestLongitude,
             };
             var oldCenter = establishment.Location.Center;
             //establishment.Location.GoogleMapZoomLevel = model.Location.GoogleMapZoomLevel;
             //establishment.Location.Center = new Coordinates
             //{
             //    Latitude = model.Location.CenterLatitude,
             //    Longitude = model.Location.CenterLongitude
             //};
             //establishment.Location.BoundingBox = new BoundingBox
             //{
             //    Northeast = new Coordinates
             //    {
             //        Latitude = model.Location.BoundingBoxNortheastLatitude,
             //        Longitude = model.Location.BoundingBoxNortheastLongitude,
             //    },
             //    Southwest = new Coordinates
             //    {
             //        Latitude = model.Location.BoundingBoxSouthwestLatitude,
             //        Longitude = model.Location.BoundingBoxSouthwestLongitude,
             //    },
             //};
             //_establishments.UnitOfWork.SaveChanges();
             //_objectCommander.Update(establishment, true);
             //_entities.Update(establishment);
             _updateEstablishment.Handle(command);
             _unitOfWork.SaveChanges();
             if (!oldCenter.HasValue)
             {
                 var builder = new SupplementalLocationPlacesBuilder(establishment.RevisionId);
                 var thread = new Thread(builder.Build);
                 thread.Start();
             }
             SetFeedbackMessage(string.Format("Successfully located {0}", establishment.TranslatedName));
             return Redirect(string.Format("/{0}", model.ReturnUrl));
         }
     }
     return HttpNotFound();
 }
コード例 #2
0
        public HttpResponseMessage ValidateParentId(int establishmentId, EstablishmentApiScalarModel model)
        {
            //System.Threading.Thread.Sleep(2000); // test api latency

            model.Id = establishmentId;

            var command = new UpdateEstablishment(model.Id, User);
            Mapper.Map(model, command);
            var validationResult = _updateValidator.Validate(command);
            var propertyName = command.PropertyName(y => y.ParentId);

            Func<ValidationFailure, bool> forText = x => x.PropertyName == propertyName;
            if (validationResult.Errors.Any(forText))
                return Request.CreateResponse(HttpStatusCode.BadRequest,
                    validationResult.Errors.First(forText).ErrorMessage, "text/plain");

            return Request.CreateResponse(HttpStatusCode.OK);
        }
コード例 #3
0
        private void Build(int retryCount)
        {
            _queryProcessor = ServiceProviderLocator.Current.GetService<IProcessQueries>();
            _updateEstablishment = ServiceProviderLocator.Current.GetService<IHandleCommands<UpdateEstablishment>>();
            _unitOfWork = ServiceProviderLocator.Current.GetService<IUnitOfWork>();
            _placeFinder = ServiceProviderLocator.Current.GetService<IConsumePlaceFinder>();
            try
            {
                var establishment = _queryProcessor.Execute(new GetEstablishmentByIdQuery(_establishmentId));
                if (!establishment.Location.Center.HasValue) return;

                var latitude = establishment.Location.Center.Latitude;
                var longitude = establishment.Location.Center.Longitude;
                if (!latitude.HasValue || !longitude.HasValue) return;

                var result = _placeFinder.Find(new PlaceByCoordinates(latitude.Value, longitude.Value)).SingleOrDefault();
                if (result == null) return;
                if (!result.WoeId.HasValue)
                {
                    throw new NotSupportedException(string.Format(
                        "Could not find WOE ID for coordinates {0},{1}", latitude, longitude));
                }
                //var place = _placeFactory.FromWoeId(result.WoeId.Value);
                var place = _queryProcessor.Execute(
                    new GetPlaceByWoeIdQuery
                    {
                        WoeId = result.WoeId.Value,
                    });
                var places = place.Ancestors.OrderByDescending(n => n.Separation).Select(a => a.Ancestor).ToList();
                places.Add(place);
                var command = new UpdateEstablishment
                {
                    Id = establishment.RevisionId,
                    PlaceIds = places.Select(p => p.RevisionId).ToArray(),
                };
                _updateEstablishment.Handle(command);
                //_establishment.Location.Places.Clear();
                //_establishment.Location.Places = places;
                //_objectCommander.Update(_establishment, true);
                //_entities.Update(_establishment);
                _unitOfWork.SaveChanges();
            }
            catch (Exception ex)
            {
                var exceptionLogger = ServiceProviderLocator.Current.GetService<ILogExceptions>();
                exceptionLogger.LogException(ex);

                if (ex is NotSupportedException)
                {
                    retryCount = 3;
                }

                if (retryCount < 2)
                {
                    Build(++retryCount);
                }
            }
        }
コード例 #4
0
        public HttpResponseMessage Put(int id, EstablishmentApiScalarModel model)
        {
            //System.Threading.Thread.Sleep(2000); // test api latency

            var entity = _queryProcessor.Execute(new EstablishmentById(id));
            if (entity == null) throw new HttpResponseException(HttpStatusCode.NotFound);

            model.Id = id;
            var command = new UpdateEstablishment(id, User);
            Mapper.Map(model, command);

            try
            {
                _updateHandler.Handle(command);
            }
            catch (ValidationException ex)
            {
                var badRequest = Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message, "text/plain");
                return badRequest;
            }

            var response = Request.CreateResponse(HttpStatusCode.OK, "Establishment was successfully updated.");
            return response;
        }