示例#1
0
        public ActionResult RemoveEntry(RemoveEntryViewModel 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"));
            }

            var entry       = list.Entries.FirstOrDefault(x => x.GeneratedId == model.EntryId);
            var currentUser = DataContext.Users.Find(HttpContext.GetOwinContext().Authentication.User.Identity.GetUserId <int>());

            if (entry == null || (entry.SecretKey != model.EntrySecret && (currentUser.FRUser == null || entry.FRUser.Id != currentUser.FRUser.Id)))
            {
                AddErrorNotification($"Could not find entry id '{model.EntryId}' in list '{list.Name}'.");
                return(RedirectToRoute("PinglistDirect", new { model.ListId }));
            }

            list.Entries.Remove(entry);
            AddSuccessNotification($"The entry for user '{entry.FRUser.Username}' has been removed.");
            DataContext.SaveChanges();

            return(RedirectToRoute("PinglistDirect", new { model.ListId, model.SecretKey }));
        }
示例#2
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 }));
        }
示例#3
0
        public ActionResult ManageList(EditPinglistViewModel model)
        {
            var list = PinglistHelpers.GetPinglist(model.ListId, false, DataContext);

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

            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("Pinglist"));
            }

            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 }));
            }

            list.Name             = model.Name;
            list.IsPublic         = model.IsPublic;
            list.PinglistCategory = Request.IsAuthenticated && model.NewPinglistCategory.HasValue && list.Creator != null?DataContext.PinglistCategories.FirstOrDefault(x => x.Owner.Id == list.Creator.Id && x.Id == model.NewPinglistCategory.Value) : null;

            list.Format = JsonConvert.SerializeObject(model.Format);

            DataContext.SaveChanges();

            return(RedirectToRoute("PinglistDirect", new { model.ListId, model.SecretKey }));
        }
示例#4
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 }));
        }
示例#5
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 }));
        }
示例#6
0
        public override async Task JobTask()
        {
            using (var ctx = new DataContext())
            {
                var list = PinglistHelpers.GetPinglist(RelatedEntityId, false, ctx);

                var usernames = _csv.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                foreach (var username in usernames)
                {
                    try
                    {
                        if (username.All(char.IsDigit))
                        {
                            await PinglistHelpers.AddEntryToList(list, null, int.Parse(username), null, ctx);
                        }
                        else
                        {
                            await PinglistHelpers.AddEntryToList(list, username, null, null, ctx);
                        }
                    }
                    catch (Exception ex)
                    {
                        ReportError(ex.Message);
                    }
                }
                ctx.SaveChanges();
            }
        }
示例#7
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"));
        }
示例#8
0
        public async Task <ActionResult> AddEntry(AddEntryViewModel model)
        {
            var list = PinglistHelpers.GetPinglist(model.ListId, false, DataContext);

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

            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("Pinglist"));
            }

            try
            {
                var entry = await PinglistHelpers.AddEntryToList(list, model.Username, model.UserId, model.Remarks, DataContext);

                if (!string.IsNullOrEmpty(TempData["Success"] as string))
                {
                    TempData["Success"] += "<br/>";
                }
                TempData["Success"] += $"User '{entry.FRUser.Username}' has been added to the pinglist.";

                if (!IsOwner(list, model.SecretKey))
                {
                    TempData["NewEntry"] = (entry.GeneratedId, entry.SecretKey, entry.FRUser.Username);
                }
            }
            catch
            {
                AddErrorNotification($"Could not find user '{(model.UserId?.ToString() ?? model.Username)}' on Flight Rising. Verify the name or id is correct.");
            }
            DataContext.SaveChanges();

            return(RedirectToRoute("PinglistDirect", new { model.ListId, model.SecretKey }));
        }
示例#9
0
        public async Task <ActionResult> AddSelf(AddSelfEntryViewModel 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 (!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 { listId = model.ListId }));
            }

            var currentUser = DataContext.Users.Find(HttpContext.GetOwinContext().Authentication.User.Identity.GetUserId <int>());

            if (currentUser.FRUser == null)
            {
                AddErrorNotification($"To use this feature you need to link your Flight Rising account, you can do so <a href=\"{Url.RouteUrl("VerifyFR")}\">here</a>.");
                return(RedirectToRoute("PinglistDirect"));
            }

            try
            {
                var entry = await PinglistHelpers.AddEntryToList(list, null, currentUser.FRUser.FRId, model.Remarks, DataContext);

                AddSuccessNotification($"User '{entry.FRUser.Username}' has been added to the pinglist.");
            }
            catch
            {
                AddErrorNotification($"Could not validate the existence of user '{currentUser.FRUser.FRId}.'");
            }
            DataContext.SaveChanges();

            return(RedirectToRoute("PinglistDirect", new { model.ListId, model.SecretKey }));
        }
示例#10
0
        public ActionResult ImportPinglist(ImportPingsViewModel model)
        {
            var list = PinglistHelpers.GetPinglist(model.ListId, false, DataContext);

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

            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("Pinglist"));
            }

            if (!string.IsNullOrWhiteSpace(model.CSV))
            {
                var jobResult = JobManager.StartNewJob(new ImportCSVPinglist(model.ListId, model.CSV));
                AddInfoNotification($"Your pinglist is being imported 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 }));
        }
示例#11
0
        public ActionResult ManageEntry(ManagePinglistEntryViewModel 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"));
            }

            var entry = list.Entries.FirstOrDefault(x => x.GeneratedId == model.EntryViewModel.EntryId);

            if (entry == null || entry.SecretKey != model.EntryViewModel.SecretKey)
            {
                AddErrorNotification($"Could not find entry id '{model.EntryViewModel.EntryId}' in list '{list.Name}'");
                return(RedirectToRoute("PinglistDirect", new { model.ListId, model.SecretKey }));
            }

            entry.Remarks = model.EntryViewModel.Remarks;
            DataContext.SaveChanges();

            AddInfoNotification($"Entry '{entry.GeneratedId} ' updated.");
            return(RedirectToRoute("PinglistDirect", new { model.ListId, model.SecretKey }));
        }
示例#12
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));
        }