示例#1
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();
            }
        }
示例#2
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 }));
        }
示例#3
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 }));
        }