コード例 #1
0
ファイル: SecurityRepository.cs プロジェクト: Ricium/Wetu
        public Company AddCompany(Company ins)
        {
            DataBaseConnection dbConn = new DataBaseConnection();
            SqlConnection con = dbConn.SqlConn();
            con.Open();

            SqlCommand cmdI = con.CreateCommand();
            SqlTransaction trx = con.BeginTransaction(CommonStrings.InsertTransaction);

            cmdI.Connection = con;
            cmdI.Transaction = trx;

            try
            {
                cmdI.Parameters.Clear();
                cmdI.CommandText = CommonStrings.InsertCompany;
                cmdI.CommandType = System.Data.CommandType.StoredProcedure;
                cmdI.Parameters.AddWithValue("@Name", ins.Name);
                cmdI.Parameters.AddWithValue("@RoleId", ins.RoleId);
                cmdI.Parameters.AddWithValue("@Removed", ins.Removed);
                ins.CompanyId = (int)cmdI.ExecuteScalar();

                trx.Commit();
                cmdI.Connection.Close();
            }
            catch (SqlException ex)
            {
                if (trx != null) trx.Rollback();
            }
            finally
            {
                if (con.State != ConnectionState.Closed)
                {
                    con.Close();
                }

                con.Dispose();
                cmdI.Dispose();
                trx.Dispose();
            }

            return ins;
        }
コード例 #2
0
ファイル: AccountController.cs プロジェクト: Ricium/Wetu
        public ActionResult RegisterCompany(RegisterCompanyModel model)
        {
            if (ModelState.IsValid)
            {
                // Attempt to register the comapny
                string rolename = "u_" + model.CompanyName;
                Roles.CreateRole(rolename);

                // Add Company to Database
                Company comp = new Company();
                comp.Name = model.CompanyName;
                comp.RoleId = secRep.GetRoleId(rolename);
                comp.Removed = false;
                comp = secRep.AddCompany(comp);

                RegisterUserModel userNew = new RegisterUserModel();
                userNew.CompanyRole = rolename;

                return RedirectToAction("RegisterUser", "Account", new { CompanyName = model.CompanyName});
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
コード例 #3
0
ファイル: SimulateController.cs プロジェクト: Ricium/Wetu
        public JsonResult AddCompanySim(string CompanyName)
        {
            // Attempt to register the comapny
            string rolename = "u_" + CompanyName;
            Roles.CreateRole(rolename);

            // Add Company to Database
            Company comp = new Company();
            comp.Name = CompanyName;
            comp.RoleId = secRep.GetRoleId(rolename);
            comp.Removed = false;
            comp = secRep.AddCompany(comp);

            return Json(comp.CompanyId, JsonRequestBehavior.AllowGet);
        }
コード例 #4
0
ファイル: SimulateController.cs プロジェクト: Ricium/Wetu
        public ActionResult AddCompany(string CompanyName)
        {
            // Attempt to register the comapny
            string rolename = "u_" + CompanyName;
            Roles.CreateRole(rolename);

            // Add Company to Database
            Company comp = new Company();
            comp.Name = CompanyName;
            comp.RoleId = secRep.GetRoleId(rolename);
            comp.Removed = false;
            comp = secRep.AddCompany(comp);

            if(comp.CompanyId == 0)
            {
                return Content("Fail Company", "text/html");
            }
            else
            {
                return Content("Success Company", "text/html");
            }
        }