Exemplo n.º 1
0
        public ActionResult Index(SearchTracking st)
        {
            try
            {
                ObjectId id;
                if (ObjectId.TryParse(st.TrackingNumber, out id))
                {
                    //try ti search in db
                    Tracking t = _trackingCollection.AsQueryable().FirstOrDefault(x => x.Id == id);
                    if (t != null)
                    {
                        if (string.IsNullOrEmpty(t.Password) ||
                            (!string.IsNullOrWhiteSpace(st.Password) && !string.IsNullOrEmpty(t.Password) &&
                             string.Equals(st.Password, t.Password)))
                        {
                            //found and unsecured or password is OK:

                            SearchTrackingInfo si = new SearchTrackingInfo();
                            si.QrData = QRCodeHtmlHelper.CreateQrData(t.Id.ToString(), t.Password);
                            TrackableItem ti =
                                _trackableItemsCollection.AsQueryable().FirstOrDefault(x => x.Id == t.TrackingItemId);
                            TrackableItemState currentState = ti.States.FirstOrDefault(state => state.Id == t.StateId);
                            si.TrackingName                = t.Id.ToString();
                            si.TrackabeItemName            = ti.Name;
                            si.State                       = currentState.Name;
                            si.History                     = t.History;
                            si.SupportsGeolocationServices = ti.SupportsGeolocationServices;
                            ViewBag.StateNames             = new Dictionary <string, string>();
                            ti.States.ToList()
                            .ForEach(
                                s => ((Dictionary <string, string>)ViewBag.StateNames).Add(s.Id.ToString(), s.Name));
                            return(View("TrackingDetails", si));
                            //return RedirectToAction("TrackingDetails", new {trackingId = st.TrackingNumber});
                        }
                        else
                        {
                            //need password
                            ViewBag.PasswordRequired = true;
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("", Resource.PublicTrackingController_Index_The_item_with_speficied_number_wasn_t_found_in_our_system__Please_verify_your_input_);
                    }
                }
                else
                {
                    ModelState.AddModelError("TrackingNumber", Resource.PublicTrackingController_Index_Incorrect_tracking_number__Please_verify_your_input_);
                    //incorrect tracking number
                }
            }
            catch
            {
                return(View());
            }
            return(View());
        }
Exemplo n.º 2
0
 public SearchResultViewModel()
 {
     SearchItems    = new BindableCollection <SearchResult>();
     _searchTracker = new SearchTracking();
     _searchTracker.OnIntervalSearchComplete += UpdateUI;
 }