public async Task <JsonResult> ProductOfCart()
        {
            try
            {
                if (HttpContext.User.Identity.IsAuthenticated)
                {
                    string name = HttpContext.User.Identity.Name;

                    AppUser appUser = await _baselDb.AppUsers
                                      .Where(x => x.UserName == name)
                                      .Include(x => x.Cart)
                                      .SingleOrDefaultAsync();

                    if (appUser != null)
                    {
                        int?CartId = appUser.Cart.Id;

                        List <Product> productsAll = await _baselDb.Products
                                                     .Include(x => x.ProductCarts)
                                                     .Where(x => x.ProductCarts.Any(z => z.CartId == CartId))
                                                     .Include(x => x.ProductLanguages)
                                                     .Include(x => x.Images)
                                                     .ToListAsync();

                        if (productsAll != null)
                        {
                            int?cultures = HttpContext.Session.GetInt32("culture");

                            if (cultures == null)
                            {
                                cultures = GetLanguage
                                           .GetLangId();
                            }

                            List <object> list = new List <object>();

                            foreach (Product item in productsAll)
                            {
                                list.Add(new
                                {
                                    item.Id,
                                    Name  = item.ProductLanguages.Where(x => x.LanguageId == cultures).Select(x => x.Name).SingleOrDefault(),
                                    Count = item.ProductCarts.Where(x => x.CartId == CartId).Select(x => x.ProductCount).SingleOrDefault(),
                                    Image = ConvertImage(item.Images.Select(x => x.FileName).FirstOrDefault()),
                                    item.Price
                                });
                            }

                            return(Json(list));
                        }
                        return(Json("Product is not found"));
                    }
                }
                return(Json("Please, Sign In to the Site"));
            }
            catch (Exception exp)
            {
                return(Json(exp.Message));
            }
        }
Example #2
0
        public async Task <IViewComponentResult> InvokeAsync()
        {
            int?cultures = HttpContext.Session.GetInt32("culture");

            if (cultures == null)
            {
                cultures = GetLanguage
                           .GetLangId();
            }

            List <MenuLanguage> menu = await _baselDbContext.Menus
                                       .SelectMany(a => a.MenuLanguages
                                                   .Where(x => x.LanguageId == cultures)).Include(x => x.Menu)
                                       .ToListAsync();

            List <SubMenuLanguage> submenu = await _baselDbContext.SubMenus
                                             .SelectMany(a => a.SubMenuLanguages
                                                         .Where(x => x.LanguageId == cultures))
                                             .ToListAsync();

            MenuSubMenuData menuSubMenu = new MenuSubMenuData()
            {
                SubMenuLanguages = submenu,
                MenuLanguages    = menu
            };

            return(View(menuSubMenu));
        }
Example #3
0
 // MSG
 private void Awake()
 {
     foreach (var tx in m_LanguageTexts)
     {
         tx.text = GetLanguage?.Invoke(tx.name);
     }
 }
Example #4
0
        internal static async Task Main(DiscordClient Bot, GuildMemberAddEventArgs MemberObjects)
        {
            Log.Debug("GuildMemberAddEvent " + "Start...");

            GetLanguage Get_Language;
            string      GuildLanguageString = Database.DatabaseMethods.GuildConfigMethods.LanguageFind(MemberObjects.Guild.Id);

            if (GuildLanguageString == null)
            {
                Get_Language = new GetLanguage(Database.Enums.Language.ja_JP);
            }
            else
            {
                if (Enum.TryParse(GuildLanguageString, true, out Database.Enums.Language GuildLanguage))
                {
                    Get_Language = new GetLanguage(GuildLanguage);
                }
                else
                {
                    Get_Language = new GetLanguage(Database.Enums.Language.ja_JP);
                }
            }

            await Fork(Bot, MemberObjects, Get_Language).ConfigureAwait(false);

            Log.Debug("GuildMemberAddEvent " + "End...");
        }
        public static IApplicationBuilder UseStaticHttpContext(this IApplicationBuilder app)
        {
            var httpContextAccessor = app.ApplicationServices.GetRequiredService <IHttpContextAccessor>();

            GetLanguage.Configure(httpContextAccessor);
            return(app);
        }
Example #6
0
        // Not Use;
        // This is google Translate at the time↓
        //internal Lazy<DiscordMember> 怠zyな { get; }

        #endregion

        internal CommandObjects(DiscordClient Bot, MessageCreateEventArgs Message_Objects)
        {
            MessageObjects = Message_Objects;
            CommandArgs    = MessageObjects.Message.Content.Trim().Split(" ");
            string GuildLanguageString = !Message_Objects.Channel.IsPrivate ? Database.DatabaseMethods.GuildConfigMethods.LanguageFind(Message_Objects.Guild.Id) : null;

            if (GuildLanguageString != null && Enum.TryParse(GuildLanguageString, true, out Database.Enums.Language GuildLanguage))
            {
                Language     = new GetLanguage(GuildLanguage).Language_Data;
                LanguageType = GuildLanguage;
            }
            else
            {
                Language     = new GetLanguage(Database.Enums.Language.ja_JP).Language_Data;
                LanguageType = Database.Enums.Language.ja_JP;
            }

            Client            = Bot;
            Message           = Message_Objects.Message;
            Channel           = Message_Objects.Channel;
            Guild             = Message_Objects.Guild;
            Author            = Message_Objects.Author;
            MentionedUsers    = Message_Objects.MentionedUsers;
            MentionedRoles    = Message_Objects.MentionedRoles;
            MentionedChannels = Message_Objects.MentionedChannels;

            User   = Author;
            Member = Message_Objects.Guild?.GetMemberAsync(User.Id).ConfigureAwait(false).GetAwaiter().GetResult();
        }
Example #7
0
        public IActionResult SetLanguage(string culture, string returnUrl)
        {
            Response.Cookies.Append(
                CookieRequestCultureProvider.DefaultCookieName,
                CookieRequestCultureProvider.MakeCookieValue(new RequestCulture(culture)),
                new CookieOptions {
                Expires = DateTimeOffset.UtcNow.AddYears(1)
            }
                );

            var languageId = Convert.ToInt32(GetLanguage.GetLanguageId(culture, _db));

            HttpContext.Session.SetString("languageId", languageId.ToString());
            return(LocalRedirect(returnUrl));
        }
Example #8
0
        public Dictionary <string, string> GetJsonData([FromBody] GetLanguage lstParam)
        {
            string LanguageCode = lstParam.LanguageCode;
            string URL          = CurrentHostEnvironment.WebRootPath + lstParam.FilePath + "." + LanguageCode + ".json";

            if (!System.IO.File.Exists(URL))
            {
                SettingHelper settingHelper = new SettingHelper(_memoryCache);
                LanguageCode = settingHelper.GetCachedSettingValue(SettingKeys.DefaultCulture);
                URL          = CurrentHostEnvironment.WebRootPath + lstParam.FilePath + "." + LanguageCode + ".json";
            }
            var jsonString = System.IO.File.ReadAllText(URL);
            Dictionary <string, string> localizeValue = JsonSerializer.Deserialize <Dictionary <string, string> >(jsonString);

            return(localizeValue);
        }
        public async Task <IViewComponentResult> InvokeAsync()
        {
            int?cultures = HttpContext.Session.GetInt32("culture");

            if (cultures == null)
            {
                cultures = GetLanguage
                           .GetLangId();
            }

            List <SlideLanguage> slideLanguages = await _baselDbContext.Slides
                                                  .SelectMany(a => a.SlideLanguages
                                                              .Where(x => x.LanguageId == cultures)).Include(x => x.Slide)
                                                  .ToListAsync();

            return(View(slideLanguages));
        }
        private async Task <List <ProductLanguage> > GetProductLanguagesAsync(string search)
        {
            int?cultures = HttpContext.Session.GetInt32("culture");

            if (cultures == null)
            {
                cultures = GetLanguage
                           .GetLangId();
            }

            List <ProductLanguage> products = await _baselDb.Products.Include(x => x.ProductLanguages)
                                              .SelectMany(x => x.ProductLanguages).Where(z => z.LanguageId == cultures)
                                              .Where(x => x.Name.Contains(search))
                                              .Include(x => x.Product).ThenInclude(x => x.Images)
                                              .ToListAsync();

            return(products);
        }
 // API
 public void Init(string rootPath)
 {
     // Project Info
     m_ProjectName.text        = "New Project";
     m_ProjectDescription.text = "";
     m_MusicAuthor.text        = "";
     m_BeatmapAuthor.text      = "";
     // Language
     foreach (var tx in m_LanguageTexts)
     {
         tx.text = GetLanguage?.Invoke(tx.name);
     }
     // Final
     MusicSizeDirty = true;
     RootPath       = rootPath;
     GotoStep(0);
     UI_SetProjectType((int)ProjectTemplateType.Stager);
 }
Example #12
0
        public async Task <IViewComponentResult> InvokeAsync()
        {
            int?cultures = HttpContext.Session.GetInt32("culture");

            if (cultures == null)
            {
                cultures = GetLanguage
                           .GetLangId();
            }

            List <CategoryLanguage> categoryLanguages = await _baselDbContext.Categories
                                                        .Include(x => x.CategoryLanguages)
                                                        .SelectMany(x => x.CategoryLanguages)
                                                        .Where(x => x.LanguageId == cultures)
                                                        .ToListAsync();

            return(View(categoryLanguages));
        }
        public IActionResult SetLanguage(string culture, string returnUrl)
        {
            Response.Cookies.Append(
                CookieRequestCultureProvider.DefaultCookieName,
                CookieRequestCultureProvider.MakeCookieValue(new RequestCulture(culture)),
                new CookieOptions {
                Expires = DateTimeOffset.UtcNow.AddYears(1)
            }
                );

            LangId = GetLanguage.GetLangId(culture);

            if (culture == null)
            {
                LangId = 1;
            }

            HttpContext.Session.SetInt32("culture", LangId);

            return(LocalRedirect(returnUrl));
        }
        public async Task <IViewComponentResult> InvokeAsync()
        {
            try
            {
                int?cultures = HttpContext.Session.GetInt32("culture");

                if (cultures == null)
                {
                    cultures = GetLanguage
                               .GetLangId();
                }

                List <AccountMenuLanguage> accountMenuLanguages = await _baselDbContext.AccountMenus
                                                                  .SelectMany(a => a.AccountMenuLanguages
                                                                              .Where(x => x.LanguageId == cultures)).Include(x => x.AccountMenu)
                                                                  .ToListAsync();

                return(View(accountMenuLanguages));
            }
            catch (Exception)
            {
                throw;
            }
        }
Example #15
0
 public async Task <LanguageModel> GetLanguageAsync([FromBody] GetLanguage getLanguage)
 {
     return(await _mediator.Send(getLanguage));
 }
Example #16
0
        private static async Task UserProcess(DiscordClient Bot, GuildMemberRemoveEventArgs MemberObjects, GetLanguage Get_Language)
        {
            bool SelfLeave = false;

            if (Database.DatabaseMethods.AllowUsersMethods.AllowUserFind(MemberObjects.Guild.Id, MemberObjects.Member.Id, out AllowUsers DBAllowUserID))
            {
                Database.DatabaseMethods.AllowUsersMethods.AllowUserDelete(DBAllowUserID);
                SelfLeave = true;
            }

            ulong Guild_ChannelID = Database.DatabaseMethods.GuildConfigMethods.LogChannelFind(MemberObjects.Guild.Id);

            if (!Database.DatabaseMethods.GuildConfigMethods.LeaveBanFind(MemberObjects.Guild.Id))
            {
                if (Guild_ChannelID != 0)
                {
                    DiscordChannel GuildLogChannel = MemberObjects.Guild.GetChannel(Guild_ChannelID);
                    DiscordEmbed   LogChannelEmbed = new Discord​Embed​Builder()
                                                     .WithTitle(
                        SelfLeave ? string.Empty :
                        Database.DatabaseMethods.GuildConfigMethods.WhitelistFind(MemberObjects.Guild.Id) ? Get_Language.Language_Data.DBDeleteLeave :
                        Get_Language.Language_Data.DisableLeave
                        )
                                                     .WithDescription(
                        string.Format(
                            Get_Language.Language_Data.Bot_BanDescription,
                            MemberObjects.Member.Username + "#" + MemberObjects.Member.Discriminator,
                            MemberObjects.Member.Id
                            )
                        )
                                                     .WithColor(new DiscordColor(SelfLeave ? 0xFF4B00 : 0xF6AA00))
                                                     .WithTimestamp(DateTime.Now)
                                                     .WithFooter(
                        string.Format("{0} Bot", Bot.CurrentUser.Username)
                        )
                                                     .WithAuthor(Get_Language.Language_Data.Leaved);
                    await GuildLogChannel.SendMessageAsync(LogChannelEmbed);
                }
                else
                {
                    Log.Warning("Could not send from log channel");
                }
            }
            else
            {
                await MemberObjects.Member.BanAsync(default, Get_Language.Language_Data.BanReason);
Example #17
0
        public async Task <IActionResult> OrderCheckout(string result, string userId)
        {
            ViewBag.IsOrdered = false;

            if (result != null && userId != null)
            {
                if (result == "Payed")
                {
                    ViewBag.Result    = "Thank you. Your order has been received.";
                    ViewBag.Color     = "#7a9c59";
                    ViewBag.IsOrdered = true;

                    try
                    {
                        if (HttpContext.User.Identity.IsAuthenticated)
                        {
                            AppUser appUser = await _baselDb.AppUsers
                                              .Where(x => x.UserName == HttpContext.User.Identity.Name)
                                              .Where(x => x.Id == userId)
                                              .Include(x => x.BillingDetail)
                                              .Include(x => x.Cart).ThenInclude(x => x.ProductCarts)
                                              .SingleOrDefaultAsync();

                            List <ProductCart> productCarts = await _baselDb.Carts
                                                              .Where(x => x.AppUserId == appUser.Id)
                                                              .Include(x => x.ProductCarts)
                                                              .SelectMany(x => x.ProductCarts)
                                                              .Include(x => x.Product)
                                                              .ThenInclude(x => x.ProductLanguages)
                                                              .ToListAsync();

                            int?cultures = GetLanguage.GetLangId();

                            List <ProductOrder> productOrders = new List <ProductOrder>();

                            foreach (ProductCart item in productCarts)
                            {
                                productOrders.Add(new ProductOrder()
                                {
                                    ProductId    = item.ProductId,
                                    ProductCount = item.ProductCount,
                                    ProductName  = item.Product.ProductLanguages
                                                   .Where(z => z.LanguageId == cultures)
                                                   .Select(z => z.Name).SingleOrDefault(),
                                    ProductPrice = item.Product.Price
                                });
                            }

                            Random random = new Random();

                            int OrderNumber = random.Next(1, 999999);

                            string TotalPrice = HttpContext.Session.GetString("userTotalPrice");

                            if (TotalPrice != null)
                            {
                                List <Order> orders = new List <Order>();

                                string[] total = TotalPrice.Split(",");

                                decimal userTotalPrice = Convert.ToDecimal(total[0]);

                                Order order = new Order()
                                {
                                    AppUserId     = appUser.Id,
                                    AppUser       = appUser,
                                    Date          = DateTime.Now,
                                    Number        = OrderNumber,
                                    Status        = "Full",
                                    Total         = userTotalPrice,
                                    ProductOrders = productOrders
                                };

                                orders.Add(order);

                                appUser.Orders = orders;

                                await _baselDb.Orders.AddAsync(order);

                                OrderCheckOutData orderCheckOutData = new OrderCheckOutData()
                                {
                                    ProductOrders = productOrders,
                                    AppUser       = appUser
                                };

                                foreach (ProductCart item in productCarts)
                                {
                                    appUser.Cart.ProductCarts.Remove(item);
                                }

                                _baselDb.SaveChanges();

                                return(View(orderCheckOutData));
                            }
                        }
                    }
                    catch (Exception exp)
                    {
                        ViewBag.Result    = exp.Message;
                        ViewBag.Color     = "red";
                        ViewBag.IsOrdered = false;
                    }
                }
                else if (result == "Low Balance")
                {
                    ViewBag.Result    = "There is not enough balance on your card";
                    ViewBag.Color     = "red";
                    ViewBag.IsOrdered = false;
                }
                else if (result == "Not Found TotalPrice")
                {
                    ViewBag.Result    = "Amount not included";
                    ViewBag.Color     = "red";
                    ViewBag.IsOrdered = false;
                }
                else
                {
                    ViewBag.Result    = "No data found";
                    ViewBag.Color     = "red";
                    ViewBag.IsOrdered = false;
                }

                return(View());
            }
            return(RedirectToAction("Error", "Home"));
        }
Example #18
0
        private static async Task AllowUserProcess(DiscordClient Bot, GuildMemberAddEventArgs MemberObjects, GetLanguage Get_Language, AllowUsers DBAllowUserID)
        {
            if (Database.DatabaseMethods.RolesMethods.RoleFind(MemberObjects.Guild.Id, DBAllowUserID.RoleNum, out Roles DBRoleRoleNum))
            {
                DiscordRole GuildRole = MemberObjects.Guild.GetRole(DBRoleRoleNum.Uuid);

                ulong Guild_ChannelID = Database.DatabaseMethods.GuildConfigMethods.LogChannelFind(MemberObjects.Guild.Id);

                if (Guild_ChannelID != 0)
                {
                    DiscordChannel GuildLogChannel = MemberObjects.Guild.GetChannel(Guild_ChannelID);
                    DiscordEmbed   LogChannelEmbed = new Discord​Embed​Builder()
                                                     .WithTitle(Get_Language.Language_Data.JoinPass)
                                                     .WithDescription(
                        string.Format(
                            Get_Language.Language_Data.UserDescription,
                            MemberObjects.Member.Username + "#" + MemberObjects.Member.Discriminator,
                            MemberObjects.Member.Id,
                            GuildRole.Name
                            )
                        )
                                                     .WithColor(new DiscordColor(0x00B06B))
                                                     .WithTimestamp(DateTime.Now)
                                                     .WithFooter(
                        string.Format("{0} Bot", Bot.CurrentUser.Username)
                        )
                                                     .WithAuthor(Get_Language.Language_Data.AccessPermission);
                    await GuildLogChannel.SendMessageAsync(LogChannelEmbed);
                }
                else
                {
                    Log.Warning("Could not send from log channel");
                }

                RoleLevel DBRoleLevel   = Enum.Parse <RoleLevel>(DBRoleRoleNum.RoleLevel);
                bool      GuildLeaveBan = Database.DatabaseMethods.GuildConfigMethods.LeaveBanFind(MemberObjects.Guild.Id);
                if (GuildLeaveBan)
                {
                    if (DBRoleLevel == RoleLevel.Public)
                    {
                        await MemberObjects.Member.GrantRoleAsync(GuildRole);

                        DiscordEmbed WelcomeEmbed = new Discord​Embed​Builder()
                                                    .WithTitle(string.Format(Get_Language.Language_Data.WelcomeEmbedTitle, MemberObjects.Guild.Name, GuildRole.Name))
                                                    .AddField(
                            Get_Language.Language_Data.DMEmbed_Public1,
                            Get_Language.Language_Data.DMEmbed_Public2
                            )
                                                    .AddField(
                            Get_Language.Language_Data.DMEmbed_Public3,
                            Get_Language.Language_Data.DMEmbed_Public4
                            )
                                                    .AddField(
                            Get_Language.Language_Data.DMEmbed_LeaveBan1,
                            string.Format(Get_Language.Language_Data.DMEmbed_LeaveBan2, GuildRole.Name)
                            )
                                                    .WithColor(new DiscordColor(0x00B06B))
                                                    .WithTimestamp(DateTime.Now)
                                                    .WithFooter(
                            string.Format("{0} Bot", Bot.CurrentUser.Username)
                            );
                        await MemberObjects.Member.SendMessageAsync(WelcomeEmbed);
                    }
                    else if (DBRoleLevel == RoleLevel.Moderator)
                    {
                        await MemberObjects.Member.GrantRoleAsync(GuildRole);

                        DiscordEmbed WelcomeEmbed = new Discord​Embed​Builder()
                                                    .WithTitle(string.Format(Get_Language.Language_Data.WelcomeEmbedTitle, MemberObjects.Guild.Name, GuildRole.Name))
                                                    .AddField(
                            Get_Language.Language_Data.DMEmbed_Moderator1,
                            Get_Language.Language_Data.DMEmbed_Moderator2
                            )
                                                    .AddField(
                            Get_Language.Language_Data.DMEmbed_Moderator3,
                            string.Format(Get_Language.Language_Data.DMEmbed_Moderator4, Bot.CurrentUser.Username)
                            )
                                                    .AddField(
                            Get_Language.Language_Data.DMEmbed_Moderator5,
                            Get_Language.Language_Data.DMEmbed_Moderator6
                            )
                                                    .AddField(
                            Get_Language.Language_Data.DMEmbed_LeaveBan1,
                            string.Format(Get_Language.Language_Data.DMEmbed_LeaveBan2, GuildRole.Name)
                            )
                                                    .WithColor(new DiscordColor(0x00B06B))
                                                    .WithTimestamp(DateTime.Now)
                                                    .WithFooter(
                            string.Format("{0} Bot", Bot.CurrentUser.Username)
                            );
                        await MemberObjects.Member.SendMessageAsync(WelcomeEmbed);
                    }
                }
                else
                {
                    if (DBRoleLevel == RoleLevel.Public)
                    {
                        await MemberObjects.Member.GrantRoleAsync(GuildRole);

                        DiscordEmbed WelcomeEmbed = new Discord​Embed​Builder()
                                                    .WithTitle(string.Format(Get_Language.Language_Data.WelcomeEmbedTitle, MemberObjects.Guild.Name, GuildRole.Name))
                                                    .AddField(
                            Get_Language.Language_Data.DMEmbed_Public1,
                            Get_Language.Language_Data.DMEmbed_Public2
                            )
                                                    .AddField(
                            Get_Language.Language_Data.DMEmbed_Public3,
                            Get_Language.Language_Data.DMEmbed_Public4
                            )
                                                    .WithColor(new DiscordColor(0x00B06B))
                                                    .WithTimestamp(DateTime.Now)
                                                    .WithFooter(
                            string.Format("{0} Bot", Bot.CurrentUser.Username)
                            );
                        await MemberObjects.Member.SendMessageAsync(WelcomeEmbed);
                    }
                    else if (DBRoleLevel == RoleLevel.Moderator)
                    {
                        await MemberObjects.Member.GrantRoleAsync(GuildRole);

                        DiscordEmbed WelcomeEmbed = new Discord​Embed​Builder()
                                                    .WithTitle(string.Format(Get_Language.Language_Data.WelcomeEmbedTitle, MemberObjects.Guild.Name, GuildRole.Name))
                                                    .AddField(
                            Get_Language.Language_Data.DMEmbed_Moderator1,
                            Get_Language.Language_Data.DMEmbed_Moderator2
                            )
                                                    .AddField(
                            Get_Language.Language_Data.DMEmbed_Moderator3,
                            string.Format(Get_Language.Language_Data.DMEmbed_Moderator4, Bot.CurrentUser.Username)
                            )
                                                    .AddField(
                            Get_Language.Language_Data.DMEmbed_Moderator5,
                            Get_Language.Language_Data.DMEmbed_Moderator6
                            )
                                                    .WithColor(new DiscordColor(0x00B06B))
                                                    .WithTimestamp(DateTime.Now)
                                                    .WithFooter(
                            string.Format("{0} Bot", Bot.CurrentUser.Username)
                            );
                        await MemberObjects.Member.SendMessageAsync(WelcomeEmbed);
                    }
                }

                Log.Debug($"{MemberObjects.Member.Username + "#" + MemberObjects.Member.Discriminator} is allowed join");
            }
            else
            {
                await MemberObjects.Member.SendMessageAsync(Get_Language.Language_Data.RoleNumNullMessage);
            }
        }
Example #19
0
        internal override async Task Execute(CommandObjects CommandObject)
        {
            Log.Debug("Start Config");
            string[] msgs = CommandObject.CommandArgs.Remove(0);
            if (msgs.Length == 0)
            {
                await CommandObject.Message.Channel.SendMessageAsync(CommandObject.Language.EmptyText);

                return;
            }

            string config_arg = msgs[0].ToLower();

            switch (config_arg)
            {
            case "whitelist":
                bool BeforeWhitelist = Database.DatabaseMethods.GuildConfigMethods.WhitelistFind(CommandObject.Guild.Id);
                bool AfterWhitelist  = !BeforeWhitelist;
                Database.DatabaseMethods.GuildConfigMethods.WhitelistUpsert(CommandObject.Guild.Id, AfterWhitelist);

                await CommandObject.Message.Channel.SendMessageAsync(AfterWhitelist?CommandObject.Language.ConfigWhitelistTrue : CommandObject.Language.ConfigWhitelistFalse);

                break;

            case "leaveban":
                bool BeforeLeaveBan = Database.DatabaseMethods.GuildConfigMethods.LeaveBanFind(CommandObject.Guild.Id);
                bool AfterLeaveBan  = !BeforeLeaveBan;
                Database.DatabaseMethods.GuildConfigMethods.LeaveBanUpsert(CommandObject.Guild.Id, AfterLeaveBan);

                await CommandObject.Message.Channel.SendMessageAsync(AfterLeaveBan?CommandObject.Language.ConfigLeaveBanTrue : CommandObject.Language.ConfigLeaveBanFalse);

                break;

            case "prefix":
                if (msgs.Length < 2 || string.IsNullOrWhiteSpace(msgs[1]))
                {
                    await CommandObject.Message.Channel.SendMessageAsync(string.Format(CommandObject.Language.ConfigEmptyValue, config_arg));

                    return;
                }

                string AfterPublicPrefix  = msgs[1];
                string BeforePublicPrefix = Database.DatabaseMethods.GuildConfigMethods.PublicPrefixFind(CommandObject.Guild.Id);
                if (BeforePublicPrefix == null)
                {
                    BeforePublicPrefix = CommandConfig.Prefix;
                }
                Database.DatabaseMethods.GuildConfigMethods.PublicPrefixUpsert(CommandObject.Guild.Id, AfterPublicPrefix);

                await CommandObject.Message.Channel.SendMessageAsync(string.Format(CommandObject.Language.ConfigPublicPrefixChange, BeforePublicPrefix, AfterPublicPrefix));

                break;

            case "logchannel":
                if (msgs.Length < 2 || string.IsNullOrWhiteSpace(msgs[1]))
                {
                    await CommandObject.Message.Channel.SendMessageAsync(string.Format(CommandObject.Language.ConfigEmptyValue, config_arg));

                    return;
                }
                if (!ulong.TryParse(msgs[1], out ulong AfterLogChannelID))
                {
                    await CommandObject.Message.Channel.SendMessageAsync(CommandObject.Language.IdCouldntParse);

                    return;
                }

                ulong BeforeLogChannelID = Database.DatabaseMethods.GuildConfigMethods.LogChannelFind(CommandObject.Guild.Id);
                Database.DatabaseMethods.GuildConfigMethods.LogChannelIdUpsert(CommandObject.Guild.Id, AfterLogChannelID);

                if (BeforeLogChannelID == 0)
                {
                    await CommandObject.Message.Channel.SendMessageAsync(string.Format(CommandObject.Language.ConfigLogChannelIDSet, AfterLogChannelID));
                }
                else
                {
                    await CommandObject.Message.Channel.SendMessageAsync(string.Format(CommandObject.Language.ConfigLogChannelIDChange, BeforeLogChannelID, AfterLogChannelID));
                }
                break;

            case "language":
                if (msgs.Length < 2 || string.IsNullOrWhiteSpace(msgs[1]))
                {
                    await CommandObject.Message.Channel.SendMessageAsync(string.Format(CommandObject.Language.ConfigEmptyValue, config_arg));

                    return;
                }

                string AfterLanguageString = msgs[1].ToLower();

                if (!Enum.TryParse(AfterLanguageString.Replace('-', '_'), true, out Database.Enums.Language AfterLanguage))
                {
                    await CommandObject.Message.Channel.SendMessageAsync(string.Format(CommandObject.Language.ConfigLanguageNotFound, AfterLanguageString));

                    return;
                }

                string BeforeLanguage = Database.DatabaseMethods.GuildConfigMethods.LanguageFind(CommandObject.Guild.Id);
                Database.DatabaseMethods.GuildConfigMethods.LanguageUpsert(CommandObject.Guild.Id, AfterLanguage);

                GetLanguage GetAfterLanguage = new GetLanguage(AfterLanguage);

                if (BeforeLanguage == null)
                {
                    await CommandObject.Message.Channel.SendMessageAsync(string.Format(GetAfterLanguage.Language_Data.ConfigLanguageSet, Enum.GetName(typeof(Database.Enums.Language), AfterLanguage).Replace('_', '-')));
                }
                else
                {
                    await CommandObject.Message.Channel.SendMessageAsync(string.Format(GetAfterLanguage.Language_Data.ConfigLanguageChange, BeforeLanguage.Replace('_', '-'), Enum.GetName(typeof(Database.Enums.Language), AfterLanguage).Replace('_', '-')));
                }
                break;

            case "level":
                bool BeforeLevelSwitch = Database.DatabaseMethods.GuildConfigMethods.LevelSwitchFind(CommandObject.Guild.Id);
                bool AfterLevelSwitch  = !BeforeLevelSwitch;
                Database.DatabaseMethods.GuildConfigMethods.LevelSwitchUpsert(CommandObject.Guild.Id, AfterLevelSwitch);

                await CommandObject.Message.Channel.SendMessageAsync(AfterLevelSwitch?CommandObject.Language.ConfigLevelSwitchTrue : CommandObject.Language.ConfigLevelSwitchFalse);

                break;

            default:
                await CommandObject.Message.Channel.SendMessageAsync(CommandObject.Language.ConfigArgsNotFound);

                break;
            }
        }
Example #20
0
        private static async Task Fork(DiscordClient Bot, GuildMemberAddEventArgs MemberObjects, GetLanguage Get_Language)
        {
            if (!Database.DatabaseMethods.GuildConfigMethods.WhitelistFind(MemberObjects.Guild.Id))
            {
                Log.Info("Whitelist Disabled");
                return;
            }
            if (MemberObjects.Member.IsBot)
            {
                await BotProcess(Bot, MemberObjects, Get_Language).ConfigureAwait(false);

                return;
            }

            if (Database.DatabaseMethods.AllowUsersMethods.AllowUserFind(MemberObjects.Guild.Id, MemberObjects.Member.Id, out AllowUsers DBAllowUserID))
            {
                await AllowUserProcess(Bot, MemberObjects, Get_Language, DBAllowUserID).ConfigureAwait(false);

                return;
            }
            else               // if DBAllowUserID is null, processes will not be executed from here. And kick.
            {
                await DenyUserProcess(Bot, MemberObjects, Get_Language).ConfigureAwait(false);

                return;
            }
        }
Example #21
0
        private static async Task DenyUserProcess(DiscordClient Bot, GuildMemberAddEventArgs MemberObjects, GetLanguage Get_Language)
        {
            await MemberObjects.Member.SendMessageAsync(Get_Language.Language_Data.PermissionDenied);

            await MemberObjects.Member.RemoveAsync(Get_Language.Language_Data.NotAccessed);

            ulong Guild_ChannelID = Database.DatabaseMethods.GuildConfigMethods.LogChannelFind(MemberObjects.Guild.Id);

            if (Guild_ChannelID != 0)
            {
                DiscordChannel GuildLogChannel = MemberObjects.Guild.GetChannel(Guild_ChannelID);
                DiscordEmbed   LogChannelEmbed = new Discord​Embed​Builder()
                                                 .WithTitle(Get_Language.Language_Data.AccessDenied)
                                                 .WithDescription(
                    string.Format(
                        Get_Language.Language_Data.Bot_BanDescription,
                        MemberObjects.Member.Username + "#" + MemberObjects.Member.Discriminator,
                        MemberObjects.Member.Id
                        )
                    )
                                                 .WithColor(new DiscordColor(0xFF4B00))
                                                 .WithTimestamp(DateTime.Now)
                                                 .WithFooter(
                    string.Format("{0} Bot", Bot.CurrentUser.Username)
                    )
                                                 .WithAuthor(Get_Language.Language_Data.NotAccessed);
                await GuildLogChannel.SendMessageAsync(LogChannelEmbed);
            }
            else
            {
                Log.Warning("Could not send from log channel");
            }

            Log.Debug($"{MemberObjects.Member.Username + "#" + MemberObjects.Member.Discriminator} is not allowed join");
        }
Example #22
0
        private static async Task BotProcess(DiscordClient Bot, GuildMemberAddEventArgs MemberObjects, GetLanguage Get_Language)
        {
            if (Database.DatabaseMethods.RolesMethods.RoleFind(MemberObjects.Guild.Id, RoleLevel.Bot, out Roles DBRoleRoleLevel))
            {
                DiscordRole GuildRole = MemberObjects.Guild.GetRole(DBRoleRoleLevel.Uuid);
                await MemberObjects.Member.GrantRoleAsync(GuildRole);
            }
            else
            {
                Log.Warning("Could not grant role");
            }

            ulong Guild_ChannelID = Database.DatabaseMethods.GuildConfigMethods.LogChannelFind(MemberObjects.Guild.Id);

            if (Guild_ChannelID != 0)
            {
                DiscordChannel GuildLogChannel = MemberObjects.Guild.GetChannel(Guild_ChannelID);
                DiscordEmbed   LogChannelEmbed = new Discord​Embed​Builder()
                                                 .WithTitle(Get_Language.Language_Data.IsBot)
                                                 .WithDescription(
                    string.Format(
                        Get_Language.Language_Data.Bot_BanDescription,
                        MemberObjects.Member.Username + "#" + MemberObjects.Member.Discriminator,
                        MemberObjects.Member.Id
                        )
                    )
                                                 .WithColor(new DiscordColor(0x1971FF))
                                                 .WithTimestamp(DateTime.Now)
                                                 .WithFooter(
                    string.Format("{0} Bot", Bot.CurrentUser.Username)
                    )
                                                 .WithAuthor(Get_Language.Language_Data.Accessed);
                await GuildLogChannel.SendMessageAsync(LogChannelEmbed);
            }
            else
            {
                Log.Warning("Could not send from log channel");
            }

            Log.Debug($"{MemberObjects.Member.Username + "#" + MemberObjects.Member.Discriminator} is Bot");
        }
 public static GetLanguage Instance(Language language)
 {
     _language = language;
     if (_getLanguage == null)
     {
         lock (LockObj)
         {
             if (_getLanguage == null)
             {
                 return _getLanguage = new GetLanguage();
             }
         }
     }
     return _getLanguage;
 }
        public async Task <JsonResult> ProductOfCart(int?id)
        {
            try
            {
                if (id != null)
                {
                    if (HttpContext.User.Identity.IsAuthenticated)
                    {
                        string name = HttpContext.User.Identity.Name;

                        AppUser appUser = await _baselDb.AppUsers
                                          .Where(x => x.UserName == name)
                                          .Include(x => x.Cart)
                                          .SingleOrDefaultAsync();

                        Product product = null;

                        product = await _baselDb.Products.Where(x => x.Stock > 0)
                                  .Where(x => x.Id == id).SingleOrDefaultAsync();

                        if (await _signInManager.CanSignInAsync(appUser))
                        {
                            if (product != null)
                            {
                                int?CartId = null;

                                if (appUser.Cart != null)
                                {
                                    CartId = appUser.CartId;

                                    Cart cart = _baselDb.Carts.Where(x => x.Id == CartId)
                                                .Include(x => x.ProductCarts).SingleOrDefault();

                                    int ProductId = cart.ProductCarts
                                                    .Where(x => x.ProductId == id)
                                                    .Select(x => x.ProductId)
                                                    .SingleOrDefault();

                                    if (ProductId == id)
                                    {
                                        int ProductCount = cart.ProductCarts
                                                           .Where(x => x.ProductId == id)
                                                           .Select(x => x.ProductCount)
                                                           .SingleOrDefault();

                                        ProductCount++;

                                        cart.ProductCarts.Where(x => x.ProductId == id)
                                        .Select(c => { c.ProductCount = ProductCount; return(c); }).ToList();
                                    }
                                    else
                                    {
                                        ProductCart productCart = new ProductCart()
                                        {
                                            ProductId    = (int)id,
                                            CartId       = (int)CartId,
                                            ProductCount = 1
                                        };

                                        cart.ProductCarts.Add(productCart);
                                    }

                                    int productStock = product.Stock;

                                    productStock--;

                                    product.Stock = productStock;

                                    await _baselDb.SaveChangesAsync();
                                }
                                else
                                {
                                    List <ProductCart> productCarts = new List <ProductCart>()
                                    {
                                        new ProductCart()
                                        {
                                            ProductId    = (int)id,
                                            ProductCount = 1
                                        }
                                    };

                                    Cart cart = new Cart()
                                    {
                                        AppUser      = appUser,
                                        ProductCarts = productCarts
                                    };

                                    int productStock = product.Stock;

                                    productStock--;

                                    product.Stock = productStock;

                                    _baselDb.Carts.Add(cart);

                                    _baselDb.SaveChanges();

                                    Cart cartDb = _baselDb.Carts.Where(x => x.AppUserId == appUser.Id).SingleOrDefault();

                                    appUser.CartId = cartDb.Id;
                                    appUser.Cart   = cartDb;

                                    await _userManager.UpdateAsync(appUser);
                                }

                                List <Product> productsAll = await _baselDb.Products
                                                             .Include(x => x.ProductCarts)
                                                             .Where(x => x.ProductCarts.Any(z => z.CartId == CartId))
                                                             .Include(x => x.ProductLanguages)
                                                             .Include(x => x.Images)
                                                             .ToListAsync();

                                if (productsAll != null)
                                {
                                    int?cultures = HttpContext.Session.GetInt32("culture");

                                    if (cultures == null)
                                    {
                                        cultures = GetLanguage
                                                   .GetLangId();
                                    }

                                    List <object> list = new List <object>();

                                    foreach (Product item in productsAll)
                                    {
                                        list.Add(new
                                        {
                                            item.Id,
                                            Name  = item.ProductLanguages.Where(x => x.LanguageId == cultures).Select(x => x.Name).SingleOrDefault(),
                                            Count = item.ProductCarts.Where(x => x.CartId == CartId).Select(x => x.ProductCount).SingleOrDefault(),
                                            Image = ConvertImage(item.Images.Select(x => x.FileName).FirstOrDefault()),
                                            item.Price
                                        });
                                    }

                                    return(new JsonResult(list));
                                }
                            }
                            return(Json("Product is not found"));
                        }
                    }
                    return(Json("Please, Sign In to the Site"));
                }
                return(Json("Product Id is not found"));
            }
            catch (Exception exp)
            {
                return(Json(exp.Message));
            }
        }