Exemplo n.º 1
0
        public ActionResult Register(User mUser)
        {
            try
            {
                if (ModelState.IsValid)
                {

                    var users = new Users
                    {
                        ID = mUser.Id,
                        FName = mUser.FName,
                        LName = mUser.LName,
                        E_Mail = mUser.EMail,
                        Username = mUser.Username,
                        Password = mUser.Password
                    };

                    ModelsContainer db = new ModelsContainer();
                    db.Users.Add(users);
                    db.SaveChanges();
                    User u = new User();

                    return RedirectToAction("OperationResult");
                }
            }
            catch (Exception ex)
            {
                return RedirectToAction("OperationResult");
            }
            return View();
        }
Exemplo n.º 2
0
 static void Main(string[] args)
 {
     InitApplicationData();
     using (var container = new ModelsContainer())
     {
         var         records = container.Set <Record>().ToList();
         LbsOperator oper    = new LbsOperator();
         foreach (var record in records)
         {
             try
             {
                 oper.CreatePoin(record);
             }
             catch (Exception ex)
             {
                 string msg = ex.OutputMessage();
                 Console.WriteLine(msg);
             }
         }
     }
     //Task task = Task.Factory.StartNew(() =>
     //    {
     //        string path = ConfigurationManager.AppSettings["file_path"];
     //        FileOperator fo = new FileOperator(path);
     //        fo.LoadExcelData();
     //        DbOperator.InsertData(fo.DataSet);
     //    });
     //task.Wait();
     //Console.WriteLine("----Finish Read Excel Data----");
     //GetHttpContent();
     //Console.WriteLine("{0}", "----All Finish----");
     //LbsOperator.CreateDatabox("TestBox");
     //LbsOperator.CreatePoin();
     Console.ReadKey();
 }
Exemplo n.º 3
0
        public JsonResult CeateAdmin(string id, string password)
        {
            ModelsContainer        db = new ModelsContainer();
            MembershipCreateStatus createStatus;
            var user = Membership.CreateUser(id, password, null, null, null, true, null,
                                             out createStatus);

            if (createStatus == MembershipCreateStatus.Success)
            {
                Roles.AddUserToRole(id, "Admin");
                UserInformation userInformation = new UserInformation();
                userInformation.phone     = "";
                userInformation.telephone = "";
                userInformation.trueName  = "管理员";
                userInformation.UserID    = new Guid(Convert.ToString(user.ProviderUserKey));
                userInformation.UserType  = 3;
                db.UserInformation.AddObject(userInformation);
                db.SaveChanges();
                return(new JsonResult {
                    Data = id
                });
            }
            else
            {
                return(new JsonResult {
                    Data = "failed"
                });
            }
        }
Exemplo n.º 4
0
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                ModelsContainer db = new ModelsContainer();
                // Attempt to register the user
                MembershipCreateStatus createStatus;
                var user = Membership.CreateUser(model.UserName, model.Password, model.Email, null, null, true, null,
                                                 out createStatus);

                if (createStatus == MembershipCreateStatus.Success)
                {
                    FormsAuthentication.SetAuthCookie(model.UserName, false /* createPersistentCookie */);

                    UserInformation userInformation = new UserInformation();
                    userInformation.phone     = model.Phone;
                    userInformation.telephone = model.TelePhone;
                    userInformation.trueName  = model.TrueName;
                    userInformation.UserID    = new Guid(Convert.ToString(user.ProviderUserKey));
                    userInformation.UserType  = model.UserType;
                    db.UserInformation.AddObject(userInformation);
                    db.SaveChanges();

                    return(RedirectToAction("Index", "Home"));
                }

                ModelState.AddModelError("", ErrorCodeToString(createStatus));
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Exemplo n.º 5
0
        static async void GetHttpContent()
        {
            //Task task = Task.Factory.StartNew(() =>
            //    {
            try
            {
                AddressTrans at = new AddressTrans();
                using (var container = new ModelsContainer())
                {
                    var records = container.Set <Record>().ToList();
                    int cursor  = 0;
                    foreach (var record in records)
                    {
                        if (record.Lat == null || record.Lnt == null)
                        {
                            Thread.Sleep(20);
                            if (!string.IsNullOrEmpty(record.Address))
                            {
                                try
                                {
                                    string url = at.BuildeUrl(record.Address.Trim().Replace(" ", ""));
                                    await at.TransLocation(record, url);

                                    Console.WriteLine("Lat = {0}, Lnt = {1}, cursor = {2}", record.Lat, record.Lnt, cursor);
                                }
                                catch (Exception ex)
                                {
                                    string msg = ex.OutputMessage();
                                    Console.WriteLine("trans address exception {0}", msg);
                                }
                                cursor++;
                                if (cursor == 100)
                                {
                                    cursor = 0;
                                    container.SaveChanges();
                                }
                            }
                        }
                    }
                    container.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                string msg = ex.OutputMessage();
                Console.WriteLine("exception message:{0}", msg);
            }
            //});
            //task.Wait();
            Console.WriteLine("----Finish Trans Location----");
        }
Exemplo n.º 6
0
        public PartialViewResult Information()
        {
            ModelsContainer db = new ModelsContainer();

            if (User.Identity.IsAuthenticated)
            {
                var             uid   = new Guid(Convert.ToString(Membership.GetUser().ProviderUserKey));
                UserInformation model = (from userInformation in Db.UserInformation where userInformation.UserID == uid select userInformation).FirstOrDefault();
                //Return the fully populated ViewModel
                return(this.PartialView(model));
            }
            //return the model with IsAuthenticated only set since none of the
            //other properties are needed
            return(this.PartialView());
        }
Exemplo n.º 7
0
 /// <summary>
 /// ID生成函数
 /// </summary>
 /// <returns></returns>
 public static string generate()
 {
     string year = DateTime.Now.Year.ToString();
     string month = (DateTime.Now.Month < 10) ? "0" + (DateTime.Now.Month) : "" + DateTime.Now.Month;
     string day = (DateTime.Now.Day < 10) ? "0" + DateTime.Now.Day : "" + DateTime.Now.Day;
     string date = year + month + day;
     ModelsContainer db = new ModelsContainer();
     var userinstances = db.UserInstance.Where(u => u.ID.StartsWith(date)).ToList();
     if (userinstances.Count == 0){
         return date + "0001";
     }
     else {
         userinstances.Sort((x,y)=>y.ID.CompareTo(x.ID));
         return (Int64.Parse(userinstances[0].ID) + 1).ToString();
     }
 }
Exemplo n.º 8
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddDbContext <NavyBattleContext>(options => options.UseSqlServer(Configuration.GetConnectionString("sqlConnection"), x => x.MigrationsAssembly("NavyBattle.Dal")));
            services.AddControllers();
            DalContainer.RegisterRepositories(services);
            ModelsContainer.RegisterModels(services);
            ServicesContainer.RegisterServices(services);

            services.AddSwaggerGen(options =>
            {
                options.SwaggerDoc("v1", new OpenApiInfo {
                    Title = "NavyBattle", Version = "v1"
                });
            });

            services.AddAutoMapper(typeof(Startup));
        }
Exemplo n.º 9
0
        /// <summary>
        /// ID生成函数
        /// </summary>
        /// <returns></returns>
        public static string generate()
        {
            string          year          = DateTime.Now.Year.ToString();
            string          month         = (DateTime.Now.Month < 10) ? "0" + (DateTime.Now.Month) : "" + DateTime.Now.Month;
            string          day           = (DateTime.Now.Day < 10) ? "0" + DateTime.Now.Day : "" + DateTime.Now.Day;
            string          date          = year + month + day;
            ModelsContainer db            = new ModelsContainer();
            var             userinstances = db.UserInstance.Where(u => u.ID.StartsWith(date)).ToList();

            if (userinstances.Count == 0)
            {
                return(date + "0001");
            }
            else
            {
                userinstances.Sort((x, y) => y.ID.CompareTo(x.ID));
                return((Int64.Parse(userinstances[0].ID) + 1).ToString());
            }
        }
Exemplo n.º 10
0
 public JsonResult CeateAdmin(string id, string password)
 {
     ModelsContainer db = new ModelsContainer();
     MembershipCreateStatus createStatus;
     var user = Membership.CreateUser(id, password, null, null, null, true, null,
                           out createStatus);
     if (createStatus == MembershipCreateStatus.Success)
     {
         Roles.AddUserToRole(id, "Admin");
         UserInformation userInformation = new UserInformation();
         userInformation.phone = "";
         userInformation.telephone = "";
         userInformation.trueName = "管理员";
         userInformation.UserID = new Guid(Convert.ToString(user.ProviderUserKey));
         userInformation.UserType = 3;
         db.UserInformation.AddObject(userInformation);
         db.SaveChanges();
         return new JsonResult { Data = id };
     }
     else
     {
         return new JsonResult { Data = "failed" };
     }
 }
Exemplo n.º 11
0
 public Repository(ModelsContainer container)
 {
     this._container = container;
 }
Exemplo n.º 12
0
        public static void InsertData(DataSet dataSet)
        {
            if (dataSet == null)
            {
                throw new ArgumentNullException("DataSet param is null");
            }

            try
            {
                //ConcurrentDictionary<string, object> cache = new ConcurrentDictionary<string, object>();
                ICacheManager cache = new MemoryCacheManager();

                var         exceptions = new ConcurrentQueue <Exception>();
                List <Task> tasks      = new List <Task>();
                Stopwatch   stopwatch  = new Stopwatch();
                stopwatch.Start();
                using (var container = new ModelsContainer())
                {
                    foreach (DataTable dt in dataSet.Tables)
                    {
                        //Task task = Task.Factory.StartNew(() =>
                        //{
                        try
                        {
                            Console.WriteLine("----------Table name is : {0}---------", dt.TableName);
                            int cursor = 0;
                            foreach (DataRow dr in dt.Rows)
                            {
                                Record record = new Record();

                                string brandsName = dr[0].ToString();
                                var    brands     = cache.Get <Brands>(brandsName, () =>
                                {
                                    return(new Brands()
                                    {
                                        Name = brandsName
                                    });
                                });
                                record.Brands = brands;

                                string modelsName = dr[1].ToString();
                                var    models     = cache.Get <Models>(modelsName, () =>
                                {
                                    return(new Models()
                                    {
                                        Name = modelsName
                                    });
                                });
                                record.Models = models;

                                record.City = dr[2].ToString();
                                string dv      = dr[3].ToString().Replace(".", "");
                                string d       = string.Format("{0}-{1}-01", dv.Substring(0, 4), dv.Substring(4, 2)).Trim();
                                var    buyYear = cache.Get <BuyYear>(d, () =>
                                {
                                    return(new BuyYear()
                                    {
                                        Time = Convert.ToDateTime(d)
                                    });
                                });
                                record.BuyYear = buyYear;

                                d           = string.Format("{0}-01-01", dr[4].ToString());
                                record.Both = DateTime.Parse(d);
                                bool g = dr[5].ToString().Equals("男") ? true : false;
                                record.Gender  = Convert.ToBoolean(g);
                                record.Address = dr[6].ToString();
                                record.Zip     = dr[7].ToString();

                                container.Set <Record>().Add(record);
                                Console.WriteLine("address {0}, cursor = {1}, threadId = {2}", record.Address, cursor, Thread.CurrentThread.ManagedThreadId);
                                cursor++;
                                if (cursor == 100)
                                {
                                    cursor = 0;
                                    container.SaveChanges();
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            exceptions.Enqueue(ex);
                        }
                        //});
                        //tasks.Add(task);
                        container.SaveChanges();
                    }
                }

                //Task.WaitAll(tasks.ToArray());

                stopwatch.Stop();
                TimeSpan ts          = stopwatch.Elapsed;
                string   elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
                                                     ts.Hours, ts.Minutes, ts.Seconds,
                                                     ts.Milliseconds / 10);
                Console.WriteLine("RunTime " + elapsedTime);
                if (exceptions.Any())
                {
                    Console.WriteLine("Parallel have exceptions, count = {0}", exceptions.Count());
                }
            }
            catch (Exception ex)
            {
                string msg = ex.OutputMessage();
                Console.WriteLine("{0}", msg);
            }
        }
Exemplo n.º 13
0
        public PartialViewResult Information()
        {
            ModelsContainer db = new ModelsContainer();
            if (User.Identity.IsAuthenticated)
            {

                var uid = new Guid(Convert.ToString(Membership.GetUser().ProviderUserKey));
                UserInformation model = (from userInformation in Db.UserInformation where userInformation.UserID == uid select userInformation).FirstOrDefault();
                //Return the fully populated ViewModel
                return this.PartialView(model);
            }
            //return the model with IsAuthenticated only set since none of the
            //other properties are needed
            return this.PartialView();
        }
Exemplo n.º 14
0
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                ModelsContainer db = new ModelsContainer();
                // Attempt to register the user
                MembershipCreateStatus createStatus;
                var user = Membership.CreateUser(model.UserName, model.Password, model.Email, null, null, true, null,
                                      out createStatus);

                if (createStatus == MembershipCreateStatus.Success)
                {
                    FormsAuthentication.SetAuthCookie(model.UserName, false /* createPersistentCookie */);

                    UserInformation userInformation = new UserInformation();
                    userInformation.phone = model.Phone;
                    userInformation.telephone = model.TelePhone;
                    userInformation.trueName = model.TrueName;
                    userInformation.UserID = new Guid(Convert.ToString(user.ProviderUserKey));
                    userInformation.UserType = model.UserType;
                    db.UserInformation.AddObject(userInformation);
                    db.SaveChanges();

                    return RedirectToAction("Index", "Home");
                }

                ModelState.AddModelError("", ErrorCodeToString(createStatus));
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }