public static void Initialize(IServiceProvider serviceProvider)
        {
            using (var context = new DBContext(
                       serviceProvider.GetRequiredService <DbContextOptions <DBContext> >()))
            {
                // Look for any board games already in database.
                if (context.BlogPosts.Any() || context.ToDo.Any() || context.Users.Any())
                {
                    return;   // Database has been seeded
                }



                Newtonsoft.Json.Linq.JArray posts = Newtonsoft.Json.Linq.JArray.Parse(System.IO.File.ReadAllText("posts.json"));
                Newtonsoft.Json.Linq.JArray users = Newtonsoft.Json.Linq.JArray.Parse(System.IO.File.ReadAllText("users.json"));
                Newtonsoft.Json.Linq.JArray todo  = Newtonsoft.Json.Linq.JArray.Parse(System.IO.File.ReadAllText("todos.json"));


                context.BlogPosts.AddRange(Enumerable.Range(0, posts.ToArray().Length).Select(index => new BlogPost
                {
                    Id     = (int)posts[index]["id"],
                    UserId = (int)posts[index]["userId"],
                    Title  = (string)posts[index]["title"],
                    Body   = (string)posts[index]["body"]
                }).ToArray());

                context.ToDo.AddRange(Enumerable.Range(0, todo.ToArray().Length).Select(index => new ToDo
                {
                    Id        = (int)todo[index]["id"],
                    UserId    = (int)todo[index]["userId"],
                    Title     = (string)todo[index]["title"],
                    Completed = (bool)todo[index]["completed"]
                }).ToArray());

                context.Users.AddRange(Enumerable.Range(0, users.ToArray().Length).Select(index => new UserData
                {
                    Id          = (int)users[index]["id"],
                    Name        = (string)users[index]["name"],
                    UserName    = (string)users[index]["username"],
                    Email       = (string)users[index]["email"],
                    Street      = (string)users[index]["address"]["street"],
                    Suite       = (string)users[index]["address"]["suite"],
                    City        = (string)users[index]["address"]["city"],
                    Zipcode     = (string)users[index]["address"]["zipcode"],
                    Lat         = (string)users[index]["address"]["geo"]["lat"],
                    Lng         = (string)users[index]["address"]["geo"]["lng"],
                    Phone       = (string)users[index]["phone"],
                    Website     = (string)users[index]["website"],
                    CompanyName = (string)users[index]["company"]["name"],
                    CatchPhrase = (string)users[index]["company"]["catchPhrase"],
                    Bs          = (string)users[index]["company"]["bs"]
                }).ToArray());

                context.SaveChanges();
            }
        }
Esempio n. 2
0
        public IHttpActionResult SetWagesOver(dynamic query)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            System.Data.IDbConnection connection = Comm.Helper.DapperHelper.Instance;
            connection.Open();
            System.Data.IDbTransaction transaction = connection.BeginTransaction();

            try
            {
                var venueId = (Newtonsoft.Json.Linq.JObject.Parse(query.ToString()))["VenueID"].ToString();
                Newtonsoft.Json.Linq.JArray ids = ((Newtonsoft.Json.Linq.JObject.Parse(query.ToString()))["WagesIDs"]);

                using (connection)
                {
                    foreach (var item in ids.ToArray())
                    {
                        connection.Execute("UPDATE[dbo].[CoachWages] SET [State] =1, [PayTime]=@payTime WHERE WagesID=@wagesID and VenueID=@venueId", new
                        {
                            wagesID = Convert.ToInt32(item),
                            venueId = Convert.ToInt32(query.VenueID),
                            payTime = DateTime.Now,
                        }, transaction);
                    }

                    transaction.Commit();
                }

                return(Ok(Comm.ResponseModel.ResponseModelBase.Success()));
            }
            catch (Exception ex)
            {
                transaction.Rollback();
                logs.Error("设置工资发放完毕失败", ex);
                return(BadRequest());
            }
        }