コード例 #1
0
        public ActionResult Create(UserInstance userinstance)
        {
            if (ModelState.IsValid)
            {
                db.UserInstance.AddObject(userinstance);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.InstanceID = new SelectList(db.Instance, "ID", "DJH", userinstance.InstanceID);
            return(View(userinstance));
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: shfanfei/CarMatrix
        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----");
        }
コード例 #3
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();
        }
コード例 #4
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"
                });
            }
        }
コード例 #5
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));
        }
コード例 #6
0
        public ActionResult Create(SavingModels savingmodels, string submitButton)
        {
            if (ModelState.IsValid)
            {
                UserInstance userInstance = new UserInstance();
                userInstance.CreateUser = new Guid(Convert.ToString(Membership.GetUser().ProviderUserKey));
                userInstance.CreateTime = DateTime.Now;
                userInstance.Instance   = savingmodels.Instance;
                if (savingmodels.Instance.ZZRQ == null)
                {
                    savingmodels.Instance.ZZRQ = new DateTime(1900, 1, 1);
                }
                userInstance.FWZL  = savingmodels.Instance.FWZL;
                userInstance.QLRMC = savingmodels.Instance.QLRMC;
                userInstance.ID    = IDgenerator.generate();
                switch (submitButton)
                {
                case "保存":
                    userInstance.Status = (int)Status.Saved;
                    break;

                case "保存并新建下一个业务>>":
                    userInstance.Status = (int)Status.Saved;
                    break;

                case "提交":
                    userInstance.Status     = (int)Status.Submitted;
                    userInstance.CommitTime = DateTime.Now;
                    break;
                }
                db.Instance.AddObject(savingmodels.Instance);
                db.UserInstance.AddObject(userInstance);
                db.SaveChanges();
                if (submitButton == "保存并新建下一个业务>>")
                {
                    return(View("create", savingmodels));
                }
                return(RedirectToAction("Index"));
            }
            return(View());
        }
コード例 #7
0
ファイル: AdminController.cs プロジェクト: nai7/ReWeb
 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" };
     }
 }
コード例 #8
0
ファイル: DbOperator.cs プロジェクト: shfanfei/CarMatrix
        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);
            }
        }
コード例 #9
0
ファイル: MemberController.cs プロジェクト: nai7/ReWeb
        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);
        }