public virtual ActionResult Form(Guid?entityId = null)
        {
            // do not process empty Guid
            if (entityId.HasValue && entityId.Value == Guid.Empty)
            {
                return(HttpNotFound());
            }

            EstablishmentForm model;

            if (entityId.HasValue)
            {
                // only check the db when the entity id is present
                //var establishment = _establishments.FindOne(By<Establishment>.EntityId(entityId.Value));
                var establishment = _queryProcessor.Execute(new EstablishmentByGuid(entityId.Value));
                if (establishment == null)
                {
                    return(HttpNotFound());
                }
                model = Mapper.Map <EstablishmentForm>(establishment);
            }
            else
            {
                model = new EstablishmentForm {
                    EntityId = Guid.NewGuid()
                };
            }

            return(EstablishmentFormView(model));
        }
 public virtual ActionResult Put(EstablishmentForm model)
 {
     if (ModelState.IsValid)
     {
         //var establishment = Mapper.Map<Establishment>(model);
     }
     return EstablishmentFormView(model);
 }
 public virtual ActionResult Put(EstablishmentForm model)
 {
     if (ModelState.IsValid)
     {
         //var establishment = Mapper.Map<Establishment>(model);
     }
     return(EstablishmentFormView(model));
 }
 private ViewResult EstablishmentFormView(EstablishmentForm model)
 {
     model.Type.Options = GetTypeOptions();
     model.Names.Insert(0, new EstablishmentForm.EstablishmentNameForm());
     model.Names.ToList().ForEach(i =>
                                  i.TranslationToLanguage.Options = GetLanguageOptions());
     return(View(Views.form, model));
 }
            public void InBoundUrl_WithNonPutAndPostMethods_IsNotRouted()
            {
                var model = new EstablishmentForm {
                    EntityId = Guid.NewGuid()
                };
                var url = new ManagementFormsRouter.PutRoute().Url.ToAppRelativeUrl()
                          .Replace("{entityId}", model.EntityId.ToString());

                url.WithMethodsExcept(HttpVerbs.Put, HttpVerbs.Post).ShouldMapToNothing();
            }
            public void OutBoundUrl_IsNotRouted()
            {
                var model = new EstablishmentForm {
                    EntityId = Guid.NewGuid()
                };
                Expression <Func <ManagementFormsController, ActionResult> > action =
                    controller => controller.Put(model);
                var url = new ManagementFormsRouter.PutRoute().Url.ToAppRelativeUrl()
                          .Replace("{entityId}", model.EntityId.ToString());

                OutBoundRoute.Of(action).InArea(Area).AppRelativeUrl().ShouldNotEqual(url);
            }
            public void InBoundUrl_WithPutAndPostMethods_IsRouted()
            {
                var model = new EstablishmentForm {
                    EntityId = Guid.NewGuid()
                };
                Expression <Func <ManagementFormsController, ActionResult> > action =
                    controller => controller.Put(model);
                var url = new ManagementFormsRouter.PutRoute().Url.ToAppRelativeUrl()
                          .Replace("{entityId}", model.EntityId.ToString());

                url.WithMethod(HttpVerbs.Put).AndMethodArg("model", model).ShouldMapTo(action);
                url.WithMethod(HttpVerbs.Post).AndMethodArg("model", model).ShouldMapTo(action);
            }
        public virtual ActionResult Form(Guid? entityId = null)
        {
            // do not process empty Guid
            if (entityId.HasValue && entityId.Value == Guid.Empty) return HttpNotFound();

            EstablishmentForm model;
            if (entityId.HasValue)
            {
                // only check the db when the entity id is present
                //var establishment = _establishments.FindOne(By<Establishment>.EntityId(entityId.Value));
                var establishment = _queryProcessor.Execute(new EstablishmentByGuid(entityId.Value));
                if (establishment == null) return HttpNotFound();
                model = Mapper.Map<EstablishmentForm>(establishment);
            }
            else
            {
                model = new EstablishmentForm { EntityId = Guid.NewGuid() };
            }

            return EstablishmentFormView(model);
        }
        public virtual JsonResult ValidateDuplicateOption(string name, List <string> values)
        {
            var model             = new EstablishmentForm();
            var validationResults = new List <ValidationResult>();
            var validationContext = new ValidationContext(model, null, null);
            var isValid           = false;

            if (string.Compare(name, typeof(EstablishmentForm.EstablishmentNameForm).FullName, StringComparison.Ordinal) == 0)
            {
                values.ForEach(t => model.Names.Add(new EstablishmentForm.EstablishmentNameForm {
                    Text = t
                }));
                validationContext.MemberName = "AlternateNames";
                isValid = Validator.TryValidateProperty(model.Names, validationContext, validationResults);
            }
            var errorMessage = (isValid)
                ? null
                : validationResults[0].ErrorMessage;

            return(Json(new { IsValid = isValid, ErrorMessage = errorMessage, }, JsonRequestBehavior.AllowGet));
            //return true;
        }
 private ViewResult EstablishmentFormView(EstablishmentForm model)
 {
     model.Type.Options = GetTypeOptions();
     model.Names.Insert(0, new EstablishmentForm.EstablishmentNameForm());
     model.Names.ToList().ForEach(i =>
         i.TranslationToLanguage.Options = GetLanguageOptions());
     return View(Views.form, model);
 }
        public virtual JsonResult ValidateDuplicateOption(string name, List<string> values)
        {
            var model = new EstablishmentForm();
            var validationResults = new List<ValidationResult>();
            var validationContext = new ValidationContext(model, null, null);
            var isValid = false;

            if (string.Compare(name, typeof(EstablishmentForm.EstablishmentNameForm).FullName, StringComparison.Ordinal) == 0)
            {
                values.ForEach(t => model.Names.Add(new EstablishmentForm.EstablishmentNameForm { Text = t }));
                validationContext.MemberName = "AlternateNames";
                isValid = Validator.TryValidateProperty(model.Names, validationContext, validationResults);
            }
            var errorMessage = (isValid)
                ? null
                : validationResults[0].ErrorMessage;

            return Json(new { IsValid = isValid, ErrorMessage = errorMessage, }, JsonRequestBehavior.AllowGet);
            //return true;
        }
 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();
 }
 public void InBoundUrl_WithNonPutAndPostMethods_IsNotRouted()
 {
     var model = new EstablishmentForm { EntityId = Guid.NewGuid() };
     var url = new ManagementFormsRouter.PutRoute().Url.ToAppRelativeUrl()
         .Replace("{entityId}", model.EntityId.ToString());
     url.WithMethodsExcept(HttpVerbs.Put, HttpVerbs.Post).ShouldMapToNothing();
 }
 public void InBoundUrl_WithPutAndPostMethods_IsRouted()
 {
     var model = new EstablishmentForm { EntityId = Guid.NewGuid() };
     Expression<Func<ManagementFormsController, ActionResult>> action =
         controller => controller.Put(model);
     var url = new ManagementFormsRouter.PutRoute().Url.ToAppRelativeUrl()
         .Replace("{entityId}", model.EntityId.ToString());
     url.WithMethod(HttpVerbs.Put).AndMethodArg("model", model).ShouldMapTo(action);
     url.WithMethod(HttpVerbs.Post).AndMethodArg("model", model).ShouldMapTo(action);
 }
 public void OutBoundUrl_IsNotRouted()
 {
     var model = new EstablishmentForm { EntityId = Guid.NewGuid() };
     Expression<Func<ManagementFormsController, ActionResult>> action =
         controller => controller.Put(model);
     var url = new ManagementFormsRouter.PutRoute().Url.ToAppRelativeUrl()
         .Replace("{entityId}", model.EntityId.ToString());
     OutBoundRoute.Of(action).InArea(Area).AppRelativeUrl().ShouldNotEqual(url);
 }
示例#16
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());
 }