Esempio n. 1
0
        /// <summary>
        /// Deletes selected memory.
        /// </summary>
        /// <param name="obj"></param>
        private async void ExecDeleteMemoryAsync(object obj)
        {
            Memory memory = (Memory)ProductListView.ProductListUserControl.MemoryList.SelectedItem;

            Rams.Remove(memory);

            switch (App.DataSource)
            {
            case ConnectionResource.LOCALAPI:
                await new WebServiceManager <Memory>().DeleteAsync(memory);
                break;

            case ConnectionResource.LOCALMYSQL:
                using (var ctx = new MysqlDbContext(ConnectionResource.LOCALMYSQL))
                {
                    ctx.DbSetMemories.Attach(memory);
                    ctx.DbSetMemories.Remove(memory);
                    await ctx.SaveChangesAsync();
                }
                break;

            default:
                break;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Deletes selected case.
        /// </summary>
        /// <param name="obj"></param>
        private async void ExecDeleteCaseAsync(object obj)
        {
            Case pcCase = (Case)ProductListView.ProductListUserControl.CaseList.SelectedItem;

            Cases.Remove(pcCase);

            switch (App.DataSource)
            {
            case ConnectionResource.LOCALAPI:
                await new WebServiceManager <Case>().DeleteAsync(pcCase);
                break;

            case ConnectionResource.LOCALMYSQL:
                using (var ctx = new MysqlDbContext(ConnectionResource.LOCALMYSQL))
                {
                    ctx.DbSetCases.Attach(pcCase);
                    ctx.DbSetCases.Remove(pcCase);
                    await ctx.SaveChangesAsync();
                }
                break;

            default:
                break;
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Deletes selected storage component.
        /// </summary>
        /// <param name="obj"></param>
        private async void ExecDeleteStorageAsync(object obj)
        {
            Storage storageComponent = (Storage)ProductListView.ProductListUserControl.StorageList.SelectedItem;

            StorageComponents.Remove(storageComponent);

            switch (App.DataSource)
            {
            case ConnectionResource.LOCALAPI:
                await new WebServiceManager <Storage>().DeleteAsync(storageComponent);
                break;

            case ConnectionResource.LOCALMYSQL:
                using (var ctx = new MysqlDbContext(ConnectionResource.LOCALMYSQL))
                {
                    ctx.DbSetStorages.Attach(storageComponent);
                    ctx.DbSetStorages.Remove(storageComponent);
                    await ctx.SaveChangesAsync();
                }
                break;

            default:
                break;
            }
        }
        public async Task <IActionResult> Post(int id, string lang)
        {
            var model = new BlogPostViewModel();

            Utils.CheckOrRefreshUiStrings(lang);
            ViewBag.Title      = Utils.GetUiString("title.blog");
            ViewBag.ActiveLink = 1;

            var postItem = new BlogItem();

            using (var db = new MysqlDbContext(this.ConnectionString))
            {
                var post = await db.Posts.SingleOrDefaultAsync(b => b.Id == id);

                var titleImage = await db.Media.SingleOrDefaultAsync(i => i.Id == post.TitleImage);

                // TODO: add gallery
                postItem.Post       = post;
                postItem.TitleImage = titleImage;

                ViewBag.Title = $"{post.Title} | {Utils.GetUiString("title.blog")} ";
            }

            model.Post = postItem;

            return(this.View(model));
        }
        public async Task <IActionResult> Index(string lang)
        {
            var model = new HomeViewModel();

            Utils.CheckOrRefreshUiStrings(lang);
            ViewBag.Title = Utils.GetUiString("title.home");

            using (var db = new MysqlDbContext(this.ConnectionString))
            {
                model.CoreData = await db.CoreData.FirstOrDefaultAsync();

                var latestPosts = db.Posts.Where(p => p.IsPublished).Take(3);

                var blogItems = new List <BlogItem>();

                // Get related mediafiles
                foreach (var b in latestPosts)
                {
                    var blogItem = new BlogItem();

                    blogItem.Post       = b;
                    blogItem.TitleImage = await db.Media.FirstOrDefaultAsync(m => m.Id == b.TitleImage);

                    // TODO: add galleries below!

                    blogItems.Add(blogItem);
                }

                model.LatestPosts = blogItems;
            }

            return(this.View(model));
        }
Esempio n. 6
0
        private int setTaskMin()
        {
            using (MysqlDbContext dbcontext = new MysqlDbContext())
            {
                int ttaskMin = 5;
                try
                {
                    logger.DebugFormat("test!");
                    var tmptaskMin = dbcontext.m_Parameter.Where(m => m.paramkey.Equals("autoGetXMLMin")).Select(m => m.paramvalue).SingleOrDefault();
                    logger.DebugFormat("**获取远行job分钟:{0}", tmptaskMin);
                    if (!string.IsNullOrEmpty(tmptaskMin))
                    {
                        if (int.TryParse(tmptaskMin, out ttaskMin))
                        {
                            logger.DebugFormat("**获取job分钟成功:{0},currMin:{1}", tmptaskMin, ttaskMin);

                            if (ttaskMin < 5)
                            {
                                ttaskMin = 5;
                            }
                        }
                    }
                    else
                    {
                        logger.DebugFormat("**job运行失败,获取分钟:{0},默认值:{1}", tmptaskMin, ttaskMin);
                    }
                }
                catch (Exception ex)
                {
                    logger.Error("**##Mysql Error:", ex);
                }
                return(ttaskMin);
            }
        }
        /// <summary>
        /// Deletes selected worker.
        /// </summary>
        /// <param name="obj"></param>
        private async void ExecDeleteWorkerAsync(object obj)
        {
            Worker worker = (Worker)WorkerListView.WorkerListUserControl.WorkerList.SelectedItem;

            Workers.Remove(worker);

            switch (App.DataSource)
            {
            case ConnectionResource.LOCALAPI:
                await new WebServiceManager <Worker>().DeleteAsync(worker);
                break;

            case ConnectionResource.LOCALMYSQL:
                using (var ctx = new MysqlDbContext(ConnectionResource.LOCALMYSQL))
                {
                    ctx.DbSetWorkers.Attach(worker);
                    ctx.DbSetWorkers.Remove(worker);
                    await ctx.SaveChangesAsync();
                }
                break;

            default:
                break;
            }
        }
Esempio n. 8
0
        /// <summary>
        /// 根据db类型和db名称获取执行content
        /// </summary>
        public static DbContext <EmptyEntity> EmptyDb(string _dbMappingName)
        {
            var dbProvider = AntData.ORM.Common.Configuration.DBSettings.DatabaseSettings.FirstOrDefault(r => r.Name.Equals(_dbMappingName));
            var _dbType    = dbProvider?.Provider;

            if (string.IsNullOrEmpty(_dbType))
            {
                return(null);
            }

            DbContext <EmptyEntity> db;

            if (_dbType.ToLower().Contains("mysql"))
            {
                db = new MysqlDbContext <EmptyEntity>(_dbMappingName);
            }
            else
            {
                db = new SqlServerlDbContext <EmptyEntity>(_dbMappingName);
            }

#if DEBUG
            db.IsEnableLogTrace = true;
            db.OnLogTrace       = OnCustomerTraceConnection;
#endif
            return(db);
        }
Esempio n. 9
0
        /// <summary>
        /// Deletes selected GPU.
        /// </summary>
        /// <param name="obj"></param>
        private async void ExecDeleteGPUAsync(object obj)
        {
            GPU gpu = (GPU)ProductListView.ProductListUserControl.GPUList.SelectedItem;

            GPUs.Remove(gpu);

            switch (App.DataSource)
            {
            case ConnectionResource.LOCALAPI:
                await new WebServiceManager <GPU>().DeleteAsync(gpu);
                break;

            case ConnectionResource.LOCALMYSQL:
                using (var ctx = new MysqlDbContext(ConnectionResource.LOCALMYSQL))
                {
                    ctx.DbSetGPUs.Attach(gpu);
                    ctx.DbSetGPUs.Remove(gpu);
                    await ctx.SaveChangesAsync();
                }
                break;

            default:
                break;
            }
        }
Esempio n. 10
0
        public async Task <IActionResult> Index(int?id, string lang)
        {
            var model = new BlogAllViewModel();

            Utils.CheckOrRefreshUiStrings(lang);
            ViewBag.Title      = Utils.GetUiString("title.blog");
            ViewBag.ActiveLink = 1;

            using (var db = new MysqlDbContext(this.ConnectionString))
            {
                // Get Posts from DB
                var posts = await db.Posts.ToListAsync();

                var blogItems = new List <BlogItem>();

                // Get related mediafiles
                foreach (var b in posts)
                {
                    var blogItem = new BlogItem();

                    blogItem.Post       = b;
                    blogItem.TitleImage = await db.Media.FirstOrDefaultAsync(m => m.Id == b.TitleImage);

                    // TODO: add galleries below!

                    blogItems.Add(blogItem);
                }

                blogItems.OrderBy(d => d.Post.Date).ToList();
                model.FeaturedPost = blogItems.FirstOrDefault();
                model.BlogItems    = blogItems;
            }

            return(this.View(model));
        }
Esempio n. 11
0
        /// <summary>
        /// 初始化 <see cref="DefaultDataFacade"/> 类的新实例。
        /// <see cref="DefaultDataFacade"/> 类的初始化将会创建 MySQL 数据库结构。
        /// </summary>
        /// <param name="mysqlDbContext">MySQL数据上下文。</param>
        /// <param name="mongoDbContext">MongoDB数据上下文。</param>
        /// <exception cref="ArgumentNullException">
        ///     <paramref name="mysqlDbContext"/>为null
        ///     或
        ///     <paramref name="mongoDbContext"/>为null
        /// </exception>
        public DefaultDataFacade(MysqlDbContext mysqlDbContext, MongoDbContext mongoDbContext)
        {
            _mysqlDbContext = mysqlDbContext ?? throw new ArgumentNullException(nameof(mysqlDbContext));
            _mongoDbContext = mongoDbContext ?? throw new ArgumentNullException(nameof(mongoDbContext));

            // TODO: 尝试重构下面的代码以分离数据库创建检查逻辑
            _mysqlDbContext.Database.EnsureCreated();
        }
 static void Main(string[] args)
 {
     Console.WriteLine("Probando el contexto de base de datos con MySQL");
     using (var db = new MysqlDbContext())
     {
         db.Database.EnsureCreated();
     }
 }
Esempio n. 13
0
 public ActionResult Get()
 {
     using (var db = new MysqlDbContext())
     {
         var usuarios = db.Usuarios.ToList();
         return(Ok(usuarios));
     }
 }
Esempio n. 14
0
        public GroceryListController(MysqlDbContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            _context = context;
        }
Esempio n. 15
0
 public int Exist(string openid)
 {
     using (MysqlDbContext mdb = new MysqlDbContext())
     {
         var user = mdb.Users.Where(t => t.Openid == openid).FirstOrDefault();
         if (user == null)
         {
             return(0);
         }
         return(1);
     }
 }
Esempio n. 16
0
 public IHttpActionResult GoInRoom([FromBody] GoInRoom_Ac_Request RequestMod)
 {
     try
     {
         if (RequestMod.RoomId < 1 || RequestMod.LocationId < 1)
         {
             throw new ArgumentException("非法访问");
         }
         using (MysqlDbContext db = new MysqlDbContext())
         {
             var room      = db.Rooms.Where(t => t.RoomId == RequestMod.RoomId & t.IsQuit == false).FirstOrDefault();
             var roomroles = db.RoomRoles.Where(t => t.Rid == RequestMod.RoomId && t.LocationId == RequestMod.LocationId).FirstOrDefault();
             if (room == null || roomroles == null)
             {
                 throw new ArgumentException("房间不存在");
             }
             GoInRoom_Ac_Response ResponseMod = new GoInRoom_Ac_Response()
             {
                 RoomID   = room.RoomId,
                 Pnum     = room.PersonsNum,
                 Victory  = room.VictoryCondition,
                 Role     = roomroles.RoleEnum.ToString(),
                 Location = roomroles.LocationId
             };
             return(Ok(new AjaxResult()
             {
                 state = ResultType.success.ToString(), data = ResponseMod
             }));
         }
     }
     catch (MySqlException e)
     {
         LogFactory.GetLogger("").Error(Environment.NewLine + DateTime.Now + ":房间进入失败(数据库问题):" + e.Message);
         return(Ok(new AjaxResult()
         {
             state = ResultType.error.ToString(), message = "房间进入失败,请联系管理员"
         }));
     }
     catch (ArgumentException e)
     {
         return(Ok(new AjaxResult()
         {
             state = ResultType.error.ToString(), message = e.Message
         }));
     }
     catch (Exception e)
     {
         return(Ok(new AjaxResult()
         {
             state = ResultType.error.ToString(), message = "非法操作:" + e.Message
         }));
     }
 }
Esempio n. 17
0
 public IHttpActionResult GameOver([FromBody] EndAction_Ac_Request RequestMod)
 {
     try
     {
         if (RequestMod.Roomid < 1)
         {
             throw new ArgumentException("非法访问");
         }
         using (MysqlDbContext db = new MysqlDbContext())
         {
             var room      = db.Rooms.Where(t => t.RoomId == RequestMod.Roomid & t.IsQuit == false).FirstOrDefault();
             var roomroles = db.RoomRoles.Where(t => t.Rid == RequestMod.Roomid);
             if (room == null || roomroles == null)
             {
                 throw new ArgumentException("房间不存在");
             }
             db.RoomRoles.RemoveRange(roomroles);
             int i = db.SaveChanges();
             GoInRoom_Ac_Response ResponseMod = new GoInRoom_Ac_Response()
             {
                 RoomID = room.RoomId,
                 Pnum   = room.PersonsNum
             };
             return(Ok(new AjaxResult()
             {
                 state = ResultType.success.ToString(), data = ResponseMod
             }));
         }
     }
     catch (MySqlException e)
     {
         LogFactory.GetLogger("").Error(Environment.NewLine + DateTime.Now + ":记录删除失败:" + e.Message);
         return(Ok(new AjaxResult()
         {
             state = ResultType.error.ToString(), message = "记录删除失败,请重试"
         }));
     }
     catch (ArgumentException e)
     {
         return(Ok(new AjaxResult()
         {
             state = ResultType.error.ToString(), message = e.Message
         }));
     }
     catch (Exception e)
     {
         return(Ok(new AjaxResult()
         {
             state = ResultType.error.ToString(), message = "非法操作:" + e.Message
         }));
     }
 }
Esempio n. 18
0
        public void Post([FromBody] lgview v)
        {
            MysqlDbContext db = new MysqlDbContext();
            lg             g  = new lg
            {
                ip = v.ii,
                gz = v.gg,
                bs = v.bb
            };

            db.LG.Add(g);
            db.SaveChanges();
        }
Esempio n. 19
0
 public IHttpActionResult GameLogs([FromBody] GameLogs_Ac_Request RequestMod)
 {
     try
     {
         if (RequestMod.RoomId < 1)
         {
             throw new ArgumentException("非法访问");
         }
         using (MysqlDbContext db = new MysqlDbContext())
         {
             GameLogs_Ac_Response res = new GameLogs_Ac_Response();
             res.logs = db.WerewlovesLogs.Where(t => t.RoomId == RequestMod.RoomId).OrderBy(t => t.CreateTime).ToList();
             if (res.logs != null)
             {
                 return(Ok(new AjaxResult()
                 {
                     state = ResultType.success.ToString(), data = res
                 }));
             }
             else
             {
                 return(Ok(new AjaxResult()
                 {
                     state = ResultType.error.ToString(), message = "无日志记录"
                 }));
             }
         }
     }
     catch (MySqlException e)
     {
         LogFactory.GetLogger("").Error(Environment.NewLine + DateTime.Now + "GameLogs记录失败(sql):" + e.Message);
         return(Ok(new AjaxResult()
         {
             state = ResultType.error.ToString(), message = "无日志记录"
         }));
     }
     catch (ArgumentException e)
     {
         return(Ok(new AjaxResult()
         {
             state = ResultType.error.ToString(), message = e.Message
         }));
     }
     catch (Exception e)
     {
         return(Ok(new AjaxResult()
         {
             state = ResultType.error.ToString(), message = "非法操作:" + e.Message
         }));
     }
 }
        public async Task <IActionResult> Index(string lang)
        {
            var model = new PortfolioViewModel();

            Utils.CheckOrRefreshUiStrings(lang);
            ViewBag.Title      = Utils.GetUiString("title.portfolio");
            ViewBag.ActiveLink = 2;

            using (var db = new MysqlDbContext(this.ConnectionString))
            {
                var featuredItem = await db.Portfolio.FirstOrDefaultAsync(p => p.IsFeatured);
            }

            return(this.View(model));
        }
Esempio n. 21
0
 public IHttpActionResult RemoveLogs([FromBody] GameLogs_Ac_Request RequestMod)
 {
     try
     {
         if (RequestMod.RoomId < 1)
         {
             throw new ArgumentException("非法访问");
         }
         using (MysqlDbContext db = new MysqlDbContext())
         {
             var ReturnData = db.WerewlovesLogs.Where(t => t.RoomId == RequestMod.RoomId).ToList();
             db.WerewlovesLogs.RemoveRange(ReturnData);
             db.SaveChanges();
             return(Ok(new AjaxResult()
             {
                 state = ResultType.success.ToString()
             }));
         }
     }
     catch (MySqlException e)
     {
         LogFactory.GetLogger("").Error(Environment.NewLine + DateTime.Now + "RemoveLogs删除失败(sql):" + e.Message);
         return(Ok(new AjaxResult()
         {
             state = ResultType.error.ToString(), message = e.Message
         }));
     }
     catch (ArgumentException e)
     {
         return(Ok(new AjaxResult()
         {
             state = ResultType.error.ToString(), message = e.Message
         }));
     }
     catch (Exception e)
     {
         return(Ok(new AjaxResult()
         {
             state = ResultType.error.ToString(), message = "非法操作:" + e.Message
         }));
     }
 }
Esempio n. 22
0
        /// <summary>
        /// 返回随机数(强制转换)
        /// </summary>
        /// <param name="many">几位随机数,最高不超过6</param>
        /// <returns></returns>
        public static int GetByPower()
        {
            //if (many < 0 || many > 6) many = 6;
            Random r   = new Random();
            int    num = r.Next((int)Math.Pow(10, many), (int)(Math.Pow(10, many + 1) - 1));

            //double min=Math.Pow(10, many) ,max=Math.Pow(10, many + 1) - 1;
            using (MysqlDbContext db = new MysqlDbContext())
            {
                var res = db.Rooms.Where(t => t.RoomId == num && t.IsQuit == false).FirstOrDefault();
                if (res == null)
                {
                    return(num);
                }
                else
                {
                    return(GetByPower());
                }
            }
        }
        /// <summary>
        /// Loads all customers.
        /// </summary>
        public async void LoadCustomersAsync()
        {
            App.SetConnectionResource();

            switch (App.DataSource)
            {
            case ConnectionResource.LOCALAPI:
                Customers = new ObservableCollection <Customer>(await new WebServiceManager <Customer>().GetAllAsync());
                break;

            case ConnectionResource.LOCALMYSQL:
                using (var ctx = new MysqlDbContext(ConnectionResource.LOCALMYSQL))
                {
                    Customers = new ObservableCollection <Customer>(await ctx.DbSetCustomers.Include(c => c.Address).ToListAsync());
                }
                break;

            default:
                break;
            }
        }
        /// <summary>
        /// Loads all workers.
        /// </summary>
        public async void LoadWorkersAsync()
        {
            #pragma warning disable CS4014
            Application.Current.Dispatcher.BeginInvoke(new ThreadStart(() =>
            {
                try
                {
                    WaitWindow.ShowDialog();
                }
                catch (InvalidOperationException e)
                {
                }
            }));
            #pragma warning restore CS4014

            App.SetConnectionResource();

            switch (App.DataSource)
            {
            case ConnectionResource.LOCALAPI:
                Workers = new ObservableCollection <Worker>(await new WebServiceManager <Worker>().GetAllAsync());
                break;

            case ConnectionResource.LOCALMYSQL:
                using (var ctx = new MysqlDbContext(ConnectionResource.LOCALMYSQL))
                {
                    Workers = new ObservableCollection <Worker>(await ctx.DbSetWorkers.Include(w => w.Address).ToListAsync());
                }
                break;

            default:
                break;
            }

            await Application.Current.Dispatcher.BeginInvoke(new ThreadStart(() =>
            {
                WaitWindow.Close();
            }));
        }
        /// <summary>
        /// Adds or updates a customer.
        /// </summary>
        /// <param name="obj"></param>
        private async void ExecSaveCustomerAsync(object obj)
        {
            switch (App.DataSource)
            {
            case ConnectionResource.LOCALAPI:
                WebServiceManager <Customer> webServiceManager = new WebServiceManager <Customer>();
                if (Customer.Id == 0)     // Saving new customer
                {
                    await webServiceManager.PostAsync(Customer);
                }
                else     // Saving updated customer
                {
                    await webServiceManager.PutAsync(Customer);
                }
                break;

            case ConnectionResource.LOCALMYSQL:
                using (var ctx = new MysqlDbContext(ConnectionResource.LOCALMYSQL))
                {
                    if (Customer.Id == 0)     // Saving new customer
                    {
                        ctx.DbSetCustomers.Add(Customer);
                        await ctx.SaveChangesAsync();
                    }
                    else     // Saving updated customer
                    {
                        ctx.Entry(Customer).State         = EntityState.Modified;
                        ctx.Entry(Customer.Address).State = EntityState.Modified;
                        await ctx.SaveChangesAsync();
                    }
                }
                break;

            default:
                break;
            }

            CustomerView.NavigationService.Navigate(new CustomerListView());
        }
Esempio n. 26
0
        public async Task <IActionResult> CreatePost(BlogItem blogItem)
        {
            if (!ModelState.IsValid)
            {
                // Fehlerbehandlung
            }

            using (var db = new MysqlDbContext(this.ConnectionString))
            {
                var addedBlogPost = await db.Posts.AddAsync(blogItem.Post);

                var addedTitleImage = await db.Media.AddAsync(blogItem.TitleImage);

                // redirectto home if no entities were saved (because whatever)
                // TODO: return to specific error page
                if (await db.SaveChangesAsync() == 0)
                {
                    return(this.RedirectToAction("index", "home"));
                }

                // redirect directly to new blogpost
                return(this.RedirectToAction("index", "blog", new { id = addedBlogPost.Entity.Id }));
            }
        }
 public UsersController(MysqlDbContext context)
 {
     _context = context;
 }
        /// <summary>
        /// Processes the payment.
        /// Stock of products decreased, customer gets charged.
        /// </summary>
        /// <param name="obj"></param>
        private async void ExecProceedToPaymentAsync(object obj)
        {
            Cart.Customer.Money -= Cart.Total;

            switch (App.DataSource)
            {
            case ConnectionResource.LOCALAPI:
                await new WebServiceManager <Cart>().PostAsync(Cart);
                break;

            case ConnectionResource.LOCALMYSQL:
                using (var ctx = new MysqlDbContext(ConnectionResource.LOCALMYSQL))
                {
                    ctx.Entry(Cart.Customer).State = EntityState.Modified;
                    foreach (var item in Cart.Items)
                    {
                        ctx.Entry(item.Product).State = EntityState.Modified;
                    }
                    ctx.DbSetCarts.Add(Cart);
                    await ctx.SaveChangesAsync();
                }
                break;

            default:
                break;
            }

            foreach (var item in Cart.Items)
            {
                if (item.Product.Stock > 0)
                {
                    if (item.Product is CPU)
                    {
                        CPUs.Add((CPU)item.Product);
                    }
                    else if (item.Product is GPU)
                    {
                        GPUs.Add((GPU)item.Product);
                    }
                    else if (item.Product is Motherboard)
                    {
                        Motherboards.Add((Motherboard)item.Product);
                    }
                    else if (item.Product is Memory)
                    {
                        Rams.Add((Memory)item.Product);
                    }
                    else if (item.Product is Storage)
                    {
                        StorageComponents.Add((Storage)item.Product);
                    }
                    else if (item.Product is PSU)
                    {
                        PSUs.Add((PSU)item.Product);
                    }
                    else // Case
                    {
                        Cases.Add((Case)item.Product);
                    }
                }
            }
            Cart.Items.Clear();
            Cart.Total = 0;
        }
Esempio n. 29
0
 public ArticleService(MysqlDbContext dbContext)
 {
     this.dbContext = dbContext;
 }
Esempio n. 30
0
 public UserController(MysqlDbContext ctx, UserService userService)
 {
     _ctx         = ctx;
     _userService = userService;
 }