Exemplo n.º 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"));
            }
        }
Exemplo n.º 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());
        }
Exemplo n.º 3
0
        public ActionResult Create(ObjectId trackingId, Tracking tracking)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var trackingItem = _trackableItemsCollection.AsQueryable().FirstOrDefault(ti => ti.Id == tracking.TrackingItemId);

                    //delete customer info if tracking item does not support it
                    if (!trackingItem.SupportsUserInformation)
                    {
                        tracking.CustomerInformation = null;
                    }

                    tracking.CreatedDate = DateTime.Now.Date;
                    tracking.Id          = trackingId;
                    tracking.User        = User.Identity.Name;
                    tracking.History     = new List <TrackingHistoryRecord>()
                    {
                        new TrackingHistoryRecord()
                        {
                            Comment = tracking.Comment, CreatedDate = DateTime.Now, StateId = tracking.StateId
                        }
                    };

                    tracking.Password = trackingItem.IsSecured ? PasswordGenerator.CreateRandomPassword(8) : string.Empty;
                    _trackingCollection.Save(tracking);
                }
                try
                {
                    var username = Membership.GetUser().UserName.ToLower();
                    var user     =
                        _usersCollection.AsQueryable().FirstOrDefault(x => string.Equals(x.NameLowerSpace, username));
                    if (user.EnableSubscribersEmailNotifications)
                    {
                        if (tracking.CustomerInformation != null && !string.IsNullOrWhiteSpace(tracking.CustomerInformation.Email))
                        {
                            var trackingItem = _trackableItemsCollection.AsQueryable().FirstOrDefault(x => x.UserId == User.Identity.Name && x.Id == tracking.TrackingItemId);
                            var stateName    = trackingItem.States.FirstOrDefault(s => s.Id == tracking.StateId).Name;
                            SubscriberMailSettings emailSettings = new SubscriberMailSettings();
                            emailSettings.SourceEmailAddress      = user.SmtpUserName;
                            emailSettings.SmtpPassword            = user.SmtpPassword;
                            emailSettings.SmtpPort                = user.SmtpPort;
                            emailSettings.SmtpUrl                 = user.SmtpServerUrl;
                            emailSettings.UseSsl                  = user.SmtpHttps;
                            emailSettings.DestinationEmailAddress = tracking.CustomerInformation.Email;
                            emailSettings.SourceFullName          = string.Format("{0} {1}", user.FirstName, user.LastName);
                            emailSettings.DestinationFullName     = string.Format("{0} {1}", tracking.CustomerInformation.FirstName, tracking.CustomerInformation.LastName);
                            var trackingData = QRCodeHtmlHelper.CreateQrData(tracking.TrackingNumber, tracking.Password);

                            var qrUrl = QRCodeHtmlHelper.QRCode(null, trackingData, 150);

                            Mailer.NotifyNewTracking(emailSettings, tracking.TrackingNumber, stateName, tracking.Comment, trackingItem.Name, qrUrl.ToString(), tracking.Password);
                        }
                    }
                }
                catch (Exception ex)
                {
                    TempData["errorsOccured"] = string.Format("Unable to send a notification email: {0}", ex.Message);
                }
                return(RedirectToAction("PrintableVersion", "Tracking", new { id = trackingId }));
            }
            catch
            {
                return(View());
            }
        }