public ActionResult Comments()
        {
            UserManager userManager = new UserManager();

            var user = userManager.GetUser(int.Parse(Session["UserID"].ToString()));
            var list = new UserCommentManager().GetUserComments(user.ID);
            return View(list);
        }
Beispiel #2
0
        public int SendAllPendingSubscriptionNotifications(string templateFolderPath)
        {
            int        notificationsSent     = 0;
            List <int> subscriptionsNotified = new List <int>();
            List <int> subscriptionsSkipped  = new List <int>();

            var allSubscriptionMatches = GetAllSubscriptionMatches(true);
            var userManager            = new UserManager();
            NotificationManager notificationManager = new NotificationManager();

            notificationManager.TemplateFolderPath = templateFolderPath;

            foreach (var subscriptionMatch in allSubscriptionMatches)
            {
                if (subscriptionMatch.SubscriptionMatches != null && subscriptionMatch.SubscriptionMatches.Count > 0)
                {
                    bool hasItemMatches = subscriptionMatch.SubscriptionMatches.Any(m => m.ItemList.Count > 0);

                    if (hasItemMatches)
                    {
                        string summaryHTML = GetSubscriptionMatchHTMLSummary(subscriptionMatch);
                        var    userDetails = userManager.GetUser(subscriptionMatch.Subscription.UserID);

                        //prepare and send email
                        Hashtable msgParams = new Hashtable();
                        msgParams.Add("SummaryContent", summaryHTML);
                        msgParams.Add("SubscriptionTitle", subscriptionMatch.Subscription.Title);

                        msgParams.Add("UserName", userDetails.Username);
                        msgParams.Add("SubscriptionEditURL", "https://openchargemap.org/site/profile/subscriptionedit?id=" + subscriptionMatch.Subscription.ID);

                        if (!String.IsNullOrEmpty(userDetails.EmailAddress))
                        {
                            notificationManager.PrepareNotification(NotificationType.SubscriptionNotification, msgParams);
                            bool sentOK = notificationManager.SendNotification(userDetails.EmailAddress);
                            if (sentOK)
                            {
                                notificationsSent++;
                                subscriptionsNotified.Add(subscriptionMatch.Subscription.ID);
                            }
                        }
                    }
                    else
                    {
                        subscriptionsSkipped.Add(subscriptionMatch.Subscription.ID);
                    }

                    //mark all subscriptions notified where sent ok
                    var dataModel = new OCM.Core.Data.OCMEntities();
                    foreach (var subscriptionId in subscriptionsNotified)
                    {
                        var s = dataModel.UserSubscriptions.Find(subscriptionId);
                        s.DateLastNotified = DateTime.UtcNow;
                    }

                    //mark all subscriptions with no matching items as processed/skipped
                    foreach (var subscriptionId in subscriptionsSkipped)
                    {
                        var s = dataModel.UserSubscriptions.Find(subscriptionId);
                        s.DateLastNotified = DateTime.UtcNow;
                    }
                    dataModel.SaveChanges();
                }
            }
            return(notificationsSent);
        }
        public ActionResult BeginLogin(OCM.API.Common.Model.LoginModel loginModel)
        {
            if (ModelState.IsValid)
            {
                var userManager = new UserManager();

                try
                {
                    var user = userManager.GetUser(loginModel);
                    if (user != null)
                    {
                        return ProcessLoginResult(user.Identifier, user.IdentityProvider, user.Username, user.EmailAddress);
                    }
                    else
                    {
                        ViewBag.InvalidLogin = true;
                    }
                }
                catch (UserManager.PasswordNotSetException)
                {
                    return RedirectToAction("PasswordReset", new { emailAddress = loginModel.EmailAddress });
                }
            }

            ViewBag.LoginProviders = OAuthWebSecurity.RegisteredClientData;
            return View(loginModel);
        }
        public ActionResult Edit(User updateProfile)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    if (Session["UserID"] != null)
                    {
                        // TODO: Add update logic here
                        var userManager = new UserManager();
                        var user = userManager.GetUser((int)Session["UserID"]);

                        bool updatedOK = false;
                        if (user.ID == updateProfile.ID)
                        {
                            updatedOK = userManager.UpdateUserProfile(updateProfile, false);
                        }

                        if (updatedOK)
                        {
                            return RedirectToAction("Index");
                        }
                        else
                        {
                            TempData["UpdateFailed"] = true;
                        }
                    }

                    return View();
                }
                catch
                {
                    return View();
                }
            }
            return View(updateProfile);
        }
        public ActionResult Edit()
        {
            if (Session["UserID"] != null)
            {
                UserManager userManager = new UserManager();
                var user = userManager.GetUser(int.Parse(Session["UserID"].ToString()));

                return View(user);
            }
            else return View();
        }
        public ActionResult View(int id)
        {
            UserManager userManager = new UserManager();
            var user = userManager.GetUser(id);

            ViewBag.CountryList = new SelectList(new ReferenceDataManager().GetCountries(true), "ID", "Title");
            return View(user);
        }
        public ActionResult Subscriptions()
        {
            UserManager userManager = new UserManager();

            var user = userManager.GetUser(int.Parse(Session["UserID"].ToString()));
            ViewBag.UserProfile = user;

            ViewBag.ReferenceData = new ReferenceDataManager().GetCoreReferenceData();

            var list = new UserSubscriptionManager().GetUserSubscriptions(user.ID);
            return View(list);
        }
        public ActionResult Media()
        {
            UserManager userManager = new UserManager();

            var user = userManager.GetUser(int.Parse(Session["UserID"].ToString()));
            var list = new MediaItemManager().GetUserMediaItems(user.ID);
            return View(list);
        }