Exemplo n.º 1
0
        public ActionResult Index(PetSearchViewModel model)
        {
            DateTime fromTemp;
            DateTime toTemp;

            try
            {
                if (
                    DateTime.TryParse(model.From.Value.ToString(), out fromTemp) &&
                    DateTime.TryParse(model.To.Value.ToString(), out toTemp)
                    )
                {
                    TempData["FromDate"] = fromTemp;
                    TempData["ToDate"]   = toTemp;
                }
                else
                {
                    this.SetAlertMessageInTempData(Models.Shared.AlertMessageTypeEnum.Error, "El rango de fechas no es válido.");
                }
            }
            catch (Exception ex)
            {
                if (model.OptionSelected == 3)
                {
                    TempData["FromDate"] = null;
                    TempData["ToDate"]   = null;
                    this.SetAlertMessageInTempData(Models.Shared.AlertMessageTypeEnum.Error, "Seleccione algun rango de fechas.");
                }
            }

            return(RedirectToAction("Index", new { op = model.OptionSelected }));
        }
Exemplo n.º 2
0
        public ActionResult Index(int?op)
        {
            this.VerifySessionVariables();
            op = op ?? 0;
            if (op < 0 || op > 3)
            {
                op = 0;
            }

            DateTime?from; DateTime?to;
            var      list = GetMapRabioButtonList();

            SetSelectedItem(op.Value, list);
            this.SetFromToBaseOnMapOption(op.Value, out from, out to);

            var model = new PetSearchViewModel
            {
                Options = list,
                From    = from,
                To      = to,
                Points  = new List <PointAlertViewModel>()
            };

            if ((from.HasValue && to.HasValue) && (from.Value > to.Value))
            {
                this.SetAlertMessageInTempData(Models.Shared.AlertMessageTypeEnum.Error, "Seleccione un rango valido de fechas.");
            }
            else
            {
                var result = _petSearchDataLoader.SearchLostPets(from, to);
                model.Points = result.ConvertAll(x => new PointAlertViewModel
                {
                    AlertCode          = x.AlertCode.ToString(),
                    PetId              = x.PetId,
                    PetCode            = x.PetCode?.ToString(),
                    PetName            = x.PetName,
                    PetProfileImageUrl = this.GetPetImageProfile(x.PetProfileImageUrl),
                    LostDateTime       = x.LostDateTime.ToString("dd / MMM / yyyy hh:mm:ss tt"),
                    Latitude           = x.Latitude,
                    Longitude          = x.Longitude
                });
            }

            this.SetAlertMessageInViewBag();
            return(View(model));
        }