Example #1
0
        public void ResetExistingUserTokens(Guid userId)
        {
            var userTokens = _context.UserToken.Where(x => x.UserId == userId && x.Expiry > DateTime.Now).ToList();

            userTokens.ForEach(x => x.Expiry = DateTime.Now);
            _context.SaveChanges();
        }
 virtual public IActionResult Post([FromBody] T value)
 {
     // Update the db with the new item added...
     DbSet.Add(value);
     Context.SaveChanges();
     return(Ok());
 }
Example #3
0
        public OutMessage Scope([Protect(UserScope.Admin)] Chat chat, User user, UserScope scope)
        {
            var me        = Context.GetMember(null, chat);
            var target    = Context.GetMember(user, chat);
            var localizer = Context.GetLocalizer();

            if (target == null)
            {
                return(OutMessage.FromCode(localizer["TargetNotFound"]));
            }
            if (!Context.GetUser().IsSuperUser &&
                (me.Scope < target.Scope ||
                 (me.Scope != UserScope.Owner &&
                  target.Scope >= UserScope.Admin &&
                  scope >= UserScope.Admin)))
            {
                return(OutMessage.FromCode(localizer["AccessDenied"]));
            }
            var db = new RepoContext();

            target.Scope = scope;
            db.Update(target);
            db.SaveChanges();
            return(OutMessage.FromCode(localizer["UserScopeUpdated"]));
        }
Example #4
0
        public Task Consume(ConsumeContext <SaveData> context)
        {
            SaveData dataToSave = context.Message;

            using (var repoContext = new RepoContext())
            {
                foreach (var repo in context.Message.Repos)
                {
                    var original = repoContext.Repos.FirstOrDefault(r => r.full_name == repo.full_name);

                    if (original == null)
                    {
                        repoContext.Repos.Add(repo);
                    }
                    else
                    {
                        repo.id = original.id;
                        repoContext.Entry(original).CurrentValues.SetValues(repo);
                    }
                }

                repoContext.SaveChanges();
            }

            Console.WriteLine("Repos have been saved with the latest data. Details: ");
            Console.WriteLine("Count: " + dataToSave.Repos.Count);

            return(Task.FromResult(context.Message));
        }
Example #5
0
        public OutMessage Notifications([Protect(UserScope.Admin)] Chat chat, bool value)
        {
            var db        = new RepoContext();
            var localizer = Context.GetLocalizer();

            chat.Notifications = value;
            db.Update(chat);
            db.SaveChanges();

            return(OutMessage.FromCode(value ? localizer["NotificationsEnabled"] : localizer["NotificationsDisabled"]));
        }
Example #6
0
        public override void Add(Person entity)
        {
            _context.Persons.Add(entity);
            _context.SaveChanges();

            //var lastPerson = _context.Persons.Last();
            //var lastPersonOffice = lastPerson.OfficeId;
            //var officeName = _context.Offices.FirstOrDefault(o => o.Id == lastPersonOffice);
            //var personList = officeName.Persons;
            //personList.Add(lastPerson);
        }
Example #7
0
        public MessageBuilder Desync([Protect(UserScope.Owner)] Route route)
        {
            var db        = new RepoContext();
            var localizer = Context.GetLocalizer();
            var routeS    = route.ToString();

            db.Remove(route);
            db.SaveChanges();
            return(new MessageBuilder()
                   .Set(MessageFlags.Code)
                   .AddText(localizer["RouteDestroyed"])
                   .AddText(routeS));
        }
Example #8
0
        public async Task <OutMessage> Init()
        {
            var localizer = Context.GetLocalizer();
            var chat      = Context.GetChat();
            var db        = new RepoContext();

            if (chat != null)
            {
                return(OutMessage.FromCode(localizer["ChatAlreadyInitialized"]));
            }

            chat = new Chat
            {
                Controller    = Controller.Name,
                ChatId        = Message.Chat.Id,
                Language      = Message.Sender.Language,
                Notifications = true
            };
            db.Update(chat);
            db.SaveChanges();

            var user = Context.GetUser();

            var result = $"{localizer["ChatInitialized"]}";

            var info = await Controller.GetChatInfo(chat.ChatId);

            if (info.Owner == 0)
            {
                user.AssignPermissions(chat, UserScope.Owner);
                result += $"\n{user.Username} {localizer["AssignedAsOwner"]}\n{localizer["UnableToAssignOwner"]}";
                return(OutMessage.FromCode(result));
            }

            var uinfo = await Controller.GetUserInfo(info.Owner);

            var owner = User.EnsureCreated(Controller.Name, uinfo);

            owner.AssignPermissions(chat, UserScope.Owner);

            if (owner.Id == user.Id)
            {
                result += $"\n{user.Username} {localizer["AssignedAsOwner"]}";
                return(OutMessage.FromCode(result));
            }

            user.AssignPermissions(chat, UserScope.Admin);

            result += $"\n{user.Username} {localizer["AssignedAsAdmin"]}\n{owner.Username} {localizer["AssignedAsOwner"]}";
            return(OutMessage.FromCode(result));
        }
Example #9
0
        // public void Info(User user = null)
        //     => this.EnterView("user", user ?? Context.GetUser());

        public OutMessage Mute(Chat chat = null)
        {
            var me        = Context.GetMember(null, chat);
            var localizer = Context.GetLocalizer();

            if (me.Mute > MuteState.None)
            {
                return(OutMessage.FromCode(localizer["YouAlreadyMuted"]));
            }
            var db = new RepoContext();

            me.Mute = MuteState.Muted;
            db.Update(me);
            db.SaveChanges();
            return(OutMessage.FromCode(localizer["YouMuted"]));
        }
Example #10
0
        public OutMessage Destroy([Protect(UserScope.Owner)] Chat chat = null)
        {
            var localizer = Context.GetLocalizer();
            var db        = new RepoContext();

            chat ??= Context.GetChat();
            if (chat == null)
            {
                return(OutMessage.FromCode(localizer["ChatNotFound"]));
            }
            var routes = chat.Routes.Select(x => x.Route).ToList();

            db.Remove(chat);
            db.SaveChanges();
            routes.ForEach(x => x.DeleteIfNotUsed());
            return(OutMessage.FromCode(localizer["ChatDestroyed"]));
        }
Example #11
0
        public OutMessage Unmute([Protect(UserScope.Moderator)] Chat chat, User user)
        {
            var localizer = Context.GetLocalizer();
            var target    = Context.GetMember(user, chat);

            if (target == null)
            {
                return(OutMessage.FromCode(localizer["TargetNotFound"]));
            }

            var db = new RepoContext();

            target.Mute = MuteState.None;
            db.Update(target);
            db.SaveChanges();
            return(OutMessage.FromCode(localizer["UserUnmuted"]));
        }
        public bool Update(Meetings mtng)
        {
            Meetings oldMeetingdata = GetByID(mtng.Id);

            if (oldMeetingdata != null)
            {
                RepoContext.AttendeeMeeting.RemoveRange(RepoContext.AttendeeMeeting.Where(x => x.MeetingId == oldMeetingdata.Id));
                RepoContext.AttendeeMeeting.AddRange(mtng.AttendeesIds.Select(id => new AttendeeMeeting {
                    AttendeeId = id, MeetingId = mtng.Id
                }));
                oldMeetingdata.Subject    = mtng.Subject;
                oldMeetingdata.UpdateDate = DateTime.Now;
                oldMeetingdata.Agenda     = mtng.Agenda;
                oldMeetingdata.DateTime   = mtng.DateTime;
            }

            RepoContext.Entry(oldMeetingdata).State = EntityState.Modified;
            RepoContext.SaveChanges();

            return(true);
        }
Example #13
0
        public OutMessage Unmute(Chat chat = null)
        {
            var me        = Context.GetMember(null, chat);
            var localizer = Context.GetLocalizer();

            if (me.Mute == MuteState.Blocked)
            {
                return(OutMessage.FromCode(localizer["CantUnmute"]));
            }

            if (me.Mute == MuteState.None)
            {
                return(OutMessage.FromCode(localizer["NotMuted"]));
            }

            var db = new RepoContext();

            me.Mute = MuteState.None;
            db.Update(me);
            db.SaveChanges();
            return(OutMessage.FromCode(localizer["YouUnmuted"]));
        }
Example #14
0
        public OutMessage CreateChat(string controller, long chatId, User owner = null)
        {
            var db = new RepoContext();

            if (db.Chats.Any(x => x.ChatId == chatId && x.Controller == controller))
            {
                return(OutMessage.FromCode("Already exists"));
            }
            owner ??= Context.GetUser();
            var chat = new Chat {
                Controller = controller, ChatId = chatId
            };
            var member = new ChatMember
            {
                Scope = UserScope.Owner,
                User  = owner,
                Chat  = chat
            };

            db.Update(member);
            db.SaveChanges();
            return(OutMessage.FromCode("Chat created " + chat.Id));
        }
Example #15
0
 public void Save()
 {
     _context.SaveChanges();
 }
Example #16
0
        public static void SeedSoupDataIfNotExists(RepoContext context)
        {
            SoupRecipe recipe = context.SoupRecipes.Where(w => w.RecipeName == "French Onion Soup").FirstOrDefault();

            if (recipe == null)
            {
                //Source: http://www.foodnetwork.com/recipes/tyler-florence/french-onion-soup-recipe2/index.html
                recipe = new SoupRecipe()
                {
                    RecipeName       = "French Onion Soup",
                    PrepTime         = "15 min",
                    CookTime         = "55 min",
                    PrepInstructions = @"Melt the stick of butter in a large pot over medium heat. Add the onions, garlic, bay leaves, thyme, and salt and pepper and cook until the onions are very soft and caramelized, about 25 minutes. Add the wine, bring to a boil, reduce the heat and simmer until the wine has evaporated and the onions are dry, about 5 minutes. Discard the bay leaves and thyme sprigs. Dust the onions with the flour and give them a stir. Turn the heat down to medium low so the flour doesn't burn, and cook for 10 minutes to cook out the raw flour taste. Now add the beef broth, bring the soup back to a simmer, and cook for 10 minutes. Season, to taste, with salt and pepper.

When you're ready to eat, preheat the broiler. Arrange the baguette slices on a baking sheet in a single layer. Sprinkle the slices with the Gruyere and broil until bubbly and golden brown, 3 to 5 minutes.

Ladle the soup in bowls and float several of the Gruyere croutons on top.

Alternative method: Ladle the soup into bowls, top each with 2 slices of bread and top with cheese. Put the bowls into the oven to toast the bread and melt the cheese. 
",
                    NumOfServings    = "4 to 6",
                    Ingredients      = new List <RecipeIngredient>()
                    {
                        new RecipeIngredient()
                        {
                            Name     = "Unsalted butter",
                            Quantity = "1/2 cup"
                        },
                        new RecipeIngredient()
                        {
                            Name     = "Onions, sliced",
                            Quantity = "4"
                        },
                        new RecipeIngredient()
                        {
                            Name     = "garlic cloves, chopped",
                            Quantity = "2"
                        },
                        new RecipeIngredient()
                        {
                            Name     = "bay leaves",
                            Quantity = "2"
                        },
                        new RecipeIngredient()
                        {
                            Name     = "fresh thyme sprigs",
                            Quantity = "2"
                        },
                        new RecipeIngredient()
                        {
                            Name     = "Kosher salt and freshly ground black pepper",
                            Quantity = "To Taste"
                        },
                        new RecipeIngredient()
                        {
                            Name     = "red wine",
                            Quantity = "1/2 Cup"
                        },
                        new RecipeIngredient()
                        {
                            Name     = "all-purpose flour",
                            Quantity = "3 heaping tablespoons "
                        },
                        new RecipeIngredient()
                        {
                            Name     = "beef broth",
                            Quantity = "2 quarts"
                        },
                        new RecipeIngredient()
                        {
                            Name     = "baguette, sliced",
                            Quantity = "1"
                        },
                        new RecipeIngredient()
                        {
                            Name     = "grated Gruyere",
                            Quantity = "1/2 pound"
                        },
                    }
                };
                context.SoupRecipes.Add(recipe);
            }

            context.SaveChanges();
        }
Example #17
0
        public static void SeedSoupDataIfNotExists(RepoContext context)
        {
            SoupRecipe recipe = context.SoupRecipes.Where(w => w.RecipeName == "French Onion Soup").FirstOrDefault();
            if (recipe == null)
            {
                //Source: http://www.foodnetwork.com/recipes/tyler-florence/french-onion-soup-recipe2/index.html
                recipe = new SoupRecipe()
                {
                    RecipeName = "French Onion Soup",
                    PrepTime = "15 min",
                    CookTime = "55 min",
                    PrepInstructions = @"Melt the stick of butter in a large pot over medium heat. Add the onions, garlic, bay leaves, thyme, and salt and pepper and cook until the onions are very soft and caramelized, about 25 minutes. Add the wine, bring to a boil, reduce the heat and simmer until the wine has evaporated and the onions are dry, about 5 minutes. Discard the bay leaves and thyme sprigs. Dust the onions with the flour and give them a stir. Turn the heat down to medium low so the flour doesn't burn, and cook for 10 minutes to cook out the raw flour taste. Now add the beef broth, bring the soup back to a simmer, and cook for 10 minutes. Season, to taste, with salt and pepper.

            When you're ready to eat, preheat the broiler. Arrange the baguette slices on a baking sheet in a single layer. Sprinkle the slices with the Gruyere and broil until bubbly and golden brown, 3 to 5 minutes.

            Ladle the soup in bowls and float several of the Gruyere croutons on top.

            Alternative method: Ladle the soup into bowls, top each with 2 slices of bread and top with cheese. Put the bowls into the oven to toast the bread and melt the cheese.
            ",
                    NumOfServings = "4 to 6",
                    Ingredients = new List<RecipeIngredient>()
                    {
                        new RecipeIngredient()
                        {
                            Name = "Unsalted butter",
                            Quantity = "1/2 cup"
                        },
                        new RecipeIngredient()
                        {
                            Name = "Onions, sliced",
                            Quantity = "4"
                        },
                        new RecipeIngredient()
                        {
                            Name = "garlic cloves, chopped",
                            Quantity = "2"
                        },
                        new RecipeIngredient()
                        {
                            Name = "bay leaves",
                            Quantity = "2"
                        },
                        new RecipeIngredient()
                        {
                            Name = "fresh thyme sprigs",
                            Quantity = "2"
                        },
                        new RecipeIngredient()
                        {
                            Name = "Kosher salt and freshly ground black pepper",
                            Quantity = "To Taste"
                        },
                        new RecipeIngredient()
                        {
                            Name = "red wine",
                            Quantity = "1/2 Cup"
                        },
                        new RecipeIngredient()
                        {
                            Name = "all-purpose flour",
                            Quantity = "3 heaping tablespoons "
                        },
                        new RecipeIngredient()
                        {
                            Name = "beef broth",
                            Quantity = "2 quarts"
                        },
                        new RecipeIngredient()
                        {
                            Name = "baguette, sliced",
                            Quantity = "1"
                        },
                        new RecipeIngredient()
                        {
                            Name = "grated Gruyere",
                            Quantity = "1/2 pound"
                        },
                    }

                };
                context.SoupRecipes.Add(recipe);
            }

            context.SaveChanges();
        }