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; }
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); }
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); }
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"); } }