示例#1
0
        public ActionResult TrackingDetails(string trackingId)
        {
            try
            {
                ObjectId id = ObjectId.Parse(trackingId);

                Tracking           t            = _trackingCollection.AsQueryable().FirstOrDefault(x => x.Id == id);
                TrackableItem      ti           = _trackableItemsCollection.AsQueryable().FirstOrDefault(x => x.Id == t.TrackingItemId);
                TrackableItemState currentState = ti.States.FirstOrDefault(state => state.Id == t.StateId);

                ViewBag.StateNames = new Dictionary <string, string>();
                ti.States.ToList().ForEach(s => ((Dictionary <string, string>)ViewBag.StateNames).Add(s.Id.ToString(), s.Name));


                SearchTrackingInfo si = new SearchTrackingInfo();
                si.QrData                      = QRCodeHtmlHelper.CreateQrData(t.Id.ToString(), t.Password);
                si.TrackingName                = t.Id.ToString();
                si.TrackabeItemName            = ti.Name;
                si.State                       = currentState.Name;
                si.History                     = t.History;
                si.SupportsGeolocationServices = ti.SupportsGeolocationServices;

                return(View(si));
            }
            catch (Exception)
            {
                return(new HttpNotFoundResult("The tracking with a specified tracking number doesn't exist"));
            }
        }
示例#2
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());
        }
示例#3
0
        private void AddState(object obj)
        {
            var newState = new TrackableItemState();
            var dlg      = new TrackableItemStateDialog(new TrackableItemStateViewModel(newState));
            var res      = dlg.ShowDialog();

            if (res.HasValue && res.Value)
            {
                DataSource.States = new List <TrackableItemState>(DataSource.States);
                DataSource.States.Add(newState);
            }
        }
        private void AddState(object obj)
        {
            var newState = new TrackableItemState();
            var dlg = new TrackableItemStateDialog(new TrackableItemStateViewModel(newState));
            var res  = dlg.ShowDialog();

            if (res.HasValue && res.Value)
            {
                DataSource.States = new List<TrackableItemState>(DataSource.States);
                DataSource.States.Add(newState);
            }
        }
        public ActionResult CreateState(ObjectId trackableItemId, TrackableItemState state)
        {
            if (ModelState.IsValid)
            {
                state.Id = ObjectId.GenerateNewId();
                var tItem = _trackableItemsCollection.Find(Query <TrackableItem> .EQ(x => x.Id, trackableItemId)).First();
                if (tItem.States == null)
                {
                    tItem.States = new List <TrackableItemState>();
                }
                tItem.States.Add(state);
                _trackableItemsCollection.Save(tItem);

                return(RedirectToAction("Details", new { id = trackableItemId }));
            }

            return(View());
        }
        public ActionResult EditState(ObjectId trackableItemId, ObjectId stateId, TrackableItemState state)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    //updating stateid - we lost it
                    state.Id = stateId;
                    var item = _trackableItemsCollection.AsQueryable().First(x => x.Id == trackableItemId);

                    int indexOfState = item.States.Where(s => s.Id == stateId).Select(item.States.IndexOf).FirstOrDefault();
                    item.States[indexOfState] = state;

                    _trackableItemsCollection.Save(item);

                    return(RedirectToAction("Details", new { id = trackableItemId.ToString() }));
                }
                return(View());
            }
            catch
            {
                return(View());
            }
        }
示例#7
0
 public TrackableItemStateViewModel(TrackableItemState trackableItemState)
 {
     State = trackableItemState;
 }
        public ActionResult CreateState(ObjectId trackableItemId, TrackableItemState state)
        {
            if (ModelState.IsValid)
            {
                state.Id = ObjectId.GenerateNewId();
                var tItem = _trackableItemsCollection.Find(Query<TrackableItem>.EQ(x=> x.Id, trackableItemId)).First();
                if (tItem.States == null) tItem.States = new List<TrackableItemState>();
                tItem.States.Add(state);
                _trackableItemsCollection.Save(tItem);

                return RedirectToAction("Details", new { id = trackableItemId });
            }

            return View();
        }
        public ActionResult EditState(ObjectId trackableItemId, ObjectId stateId, TrackableItemState state)
        {
            try
            {

                if (ModelState.IsValid)
                {
                    //updating stateid - we lost it
                    state.Id = stateId;
                    var item = _trackableItemsCollection.AsQueryable().First(x => x.Id == trackableItemId);

                    int indexOfState = item.States.Where(s=> s.Id == stateId).Select(item.States.IndexOf).FirstOrDefault();
                    item.States[indexOfState] = state;

                    _trackableItemsCollection.Save(item);

                    return RedirectToAction("Details", new {id =  trackableItemId.ToString()});
                }
                return View();
            }
            catch
            {
                return View();
            }
        }