示例#1
0
        /// <summary>
        /// create admin account if no account exists
        /// </summary>
        public ActionResult Seed()
        {
            int count = nguoiDungRepository.GetAll().Count();

            if (count == 0)
            {
                var password = AuthHelpers.CreatePassword("123456");

                adminUow.BeginTransaction();
                try
                {
                    var nguoiDung = new HDNHD.Models.DataContexts.Nguoidung()
                    {
                        Taikhoan = "admin",
                        Isadmin  = true,
                        Matkhau  = password
                    };
                    nguoiDungRepository.Insert(nguoiDung);
                    adminUow.SubmitChanges();

                    var dangNhap = new HDNHD.Models.DataContexts.Dangnhap()
                    {
                        NguoidungID      = nguoiDung.NguoidungID,
                        Solandangnhapsai = 0
                    };
                    dangNhapRepository.Insert(dangNhap);

                    adminUow.SubmitChanges();
                    adminUow.Commit();

                    return(Content("Created user: '******' successfully!"));
                }
                catch (Exception e)
                {
                    adminUow.RollBack();
                    return(Content("Fail to create seeding user: '******'."));
                }
            }

            return(Content("Users exist. Seeding aborted!"));
        }