コード例 #1
0
        public ActionResult UpdatePinglistUsers(PinglistViewModel model)
        {
            var list = PinglistHelpers.GetPinglist(model.ListId, true, DataContext);

            if (list == null)
            {
                AddErrorNotification($"There is no pinglist with the ID '{model.ListId}'.");
                return(RedirectToRoute("PinglistDirect"));
            }

            if (!HasAccess(list, model.SecretKey))
            {
                AddErrorNotification("You do not have access to this pinglist. Make sure you are logged in or provide the correct secret key.");
                return(RedirectToRoute("PinglistDirect", new { model.ListId }));
            }

            if (!IsOwner(list, model.SecretKey))
            {
                AddErrorNotification("Only the owner can manage a pinglist. Make sure you are logged in or provide the correct secret key.");
                return(RedirectToRoute("PinglistDirect", new { model.ListId }));
            }

            var job = Task.Run(async() =>
            {
                foreach (var entry in list.Entries.Select(x => x.FRUser.FRId).ToList())
                {
                    await FRHelpers.GetOrUpdateFRUser(entry);
                }
            });
            var jobResult = JobManager.StartNewJob(new UpdatePinglist(list.GeneratedId, list.Entries.Select(x => x.FRUser.FRId).ToList()));

            AddInfoNotification($"The entries on your pinglist are being updated in the background, depending on the size this can take a while. You started this job at '{jobResult.StartTime}'.");

            return(RedirectToRoute("PinglistDirect", new { model.ListId, model.SecretKey }));
        }
コード例 #2
0
        public ActionResult MarkPinglistJobTaskRead(string listId, string secretKey, Guid jobId)
        {
            var list = PinglistHelpers.GetPinglist(listId, true, DataContext);

            if (list == null)
            {
                AddErrorNotification($"There is no pinglist with the ID '{listId}'.");
                return(RedirectToRoute("PinglistInfo"));
            }

            var model = new PinglistViewModel
            {
                Name     = list.Name,
                Owner    = list.Creator,
                ListId   = list.GeneratedId,
                IsPublic = list.IsPublic
            };

            if (Request.IsAuthenticated)
            {
                model.CurrentFRUser = DataContext.Users.Find(HttpContext.GetOwinContext().Authentication.User.Identity.GetUserId <int>()).FRUser;
            }

            if (!HasAccess(list, secretKey))
            {
                AddErrorNotification("You do not have access to this pinglist. Make sure you are logged in or provide the correct secret key.");
                return(RedirectToRoute("Pinglist"));
            }

            JobManager.MarkFinishedJobRead(jobId);

            return(RedirectToRoute("PinglistDirect", new { listId = model.ListId }));
        }
コード例 #3
0
        public ActionResult LinkExisting(PinglistViewModel model)
        {
            var list = PinglistHelpers.GetPinglist(model.ListId, false, DataContext);

            if (list == null)
            {
                AddErrorNotification($"There is no pinglist with the ID '{model.ListId}'.");
                return(RedirectToRoute("PinglistLink"));
            }

            if (list.Creator != null)
            {
                AddErrorNotification("This list is already linked to an account");
                return(RedirectToRoute("PinglistLink"));
            }

            if (list.SecretKey != model.SecretKey)
            {
                AddErrorNotification("Secret key does not match");
                return(RedirectToRoute("PinglistLink"));
            }

            int userId = HttpContext.GetOwinContext().Authentication.User.Identity.GetUserId <int>();

            list.Creator = DataContext.Users.Find(userId);
            AddSuccessNotification("Pinglist has been succesfully linked to your account");

            DataContext.SaveChanges();

            return(RedirectToRoute("PinglistDirect", new { model.ListId, model.SecretKey }));
        }
コード例 #4
0
        public ActionResult Delete(PinglistViewModel model)
        {
            var list = PinglistHelpers.GetPinglist(model.ListId, false, DataContext);

            if (list != null && IsOwner(list, model.SecretKey))
            {
                DataContext.PingListEntries.RemoveRange(list.Entries.ToList());
                DataContext.Pinglists.Remove(list);
                DataContext.SaveChanges();

                AddSuccessNotification("The pinglist has been succesfully removed.");
            }
            else
            {
                AddErrorNotification("Only the owner can manage a pinglist. Make sure you are logged in or provide the correct secret key.");
                return(RedirectToRoute("PinglistDirect", new { listId = model.ListId }));
            }

            return(RedirectToRoute("Pinglist"));
        }
コード例 #5
0
        public ActionResult List(string listId, string secretKey = null)
        {
            var list = PinglistHelpers.GetPinglist(listId, true, DataContext);

            if (list == null)
            {
                AddErrorNotification($"There is no pinglist with the ID '{listId}'.");
                return(RedirectToRoute("PinglistInfo"));
            }

            var model = new PinglistViewModel
            {
                Name     = list.Name,
                Owner    = list.Creator,
                ListId   = list.GeneratedId,
                IsPublic = list.IsPublic
            };

            if (Request.IsAuthenticated)
            {
                model.CurrentFRUser = DataContext.Users.Find(HttpContext.GetOwinContext().Authentication.User.Identity.GetUserId <int>()).FRUser;
            }

            if (!HasAccess(list, secretKey))
            {
                if (list.Entries.Any(x => x.FRUser.FRId == model.CurrentFRUser?.FRId))
                {
                    AddInfoNotification("This pinglist is private, however since you are on it you can manage your entry.");
                    var entry = list.Entries.FirstOrDefault(x => x.FRUser.Id == model.CurrentFRUser.Id);
                    model.EntriesViewModel = new PinglistEntriesViewModel
                    {
                        IsPublic        = model.IsPublic,
                        CurrentUserId   = entry.FRUser.User.Id,
                        CurrentFRUserId = entry.FRUser.FRId,
                        ListId          = list.GeneratedId,
                        PinglistEntries = new[] { new PinglistEntryViewModel {
                                                      EntryId = entry.GeneratedId, SecretKey = entry.SecretKey, FRUser = model.CurrentFRUser
                                                  } }.ToList()
                    };
                    return(View("PrivateViewList", model));
                }
                else
                {
                    AddErrorNotification("You do not have access to this pinglist. Make sure you are logged in or provide the correct secret key.");
                    return(RedirectToRoute("Pinglist"));
                }
            }
            else
            {
                model.EntriesViewModel = new PinglistEntriesViewModel
                {
                    ListId          = list.GeneratedId,
                    PinglistEntries = list.Entries.Select(x => new PinglistEntryViewModel {
                        EntryId = x.GeneratedId, SecretKey = x.SecretKey, FRUser = x.FRUser, Remarks = x.Remarks
                    }).ToList(),
                    IsPublic        = model.IsPublic,
                    CurrentUserId   = model.CurrentFRUser?.User.Id,
                    CurrentFRUserId = model.CurrentFRUser?.FRId
                }
            };
            if (IsOwner(list, secretKey))
            {
                var ownerModel = new EditPinglistViewModel {
                    Name = model.Name, Owner = model.Owner, ListId = model.ListId, CurrentFRUser = model.CurrentFRUser, EntriesViewModel = model.EntriesViewModel, IsPublic = list.IsPublic
                };
                ownerModel.EntriesViewModel.SecretKey = ownerModel.SecretKey = list.SecretKey;
                ownerModel.Format       = list.Format == null ? new EditPinglistViewModel.FormatModel() : JsonConvert.DeserializeObject <EditPinglistViewModel.FormatModel>(list.Format);
                ownerModel.CopyPinglist = $"{ownerModel.Format.Prefix}{string.Join(ownerModel.Format.Separator, ownerModel.EntriesViewModel.PinglistEntries.Select(x => $"@{x.FRUser.Username}"))}{ownerModel.Format.Postfix}";
                ownerModel.AvailableCategories.Add(new PinglistCategory {
                    Id = -1
                });
                ownerModel.AvailableCategories.AddRange(DataContext.PinglistCategories.Where(x => x.Owner.Id == ownerModel.Owner.Id).ToList());
                ownerModel.PinglistCategory = list.PinglistCategory;
                ownerModel.ShareUrl         = list.ShareUrl;
                ownerModel.FinishedJobs     = JobManager.GetUnconfirmedFinishedJobs(model.ListId);
                var activeJobs = JobManager.GetActiveJobs(list.GeneratedId.ToString());
                foreach (var job in activeJobs)
                {
                    if (!string.IsNullOrEmpty(TempData["Info"] as string))
                    {
                        TempData["Info"] += "<br/>";
                    }
                    TempData["Info"] += $"Still working on: {job.Description}";
                }
                return(View("OwnerViewList", ownerModel));
            }

            return(View("PublicViewList", model));
        }