// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ public int InsertCompany(CompanyInsertRequest model) { int id = 0; try { DataProvider.ExecuteNonQuery(GetConnection, "dbo.Company_Insert" , inputParamMapper : delegate(SqlParameterCollection paramCollection) { paramCollection.AddWithValue("@ownerId", model.OwnerId); paramCollection.AddWithValue("@Name", model.Name); paramCollection.AddWithValue("@TypeId", model.TypeId); paramCollection.AddWithValue("@Phone", model.Phone); paramCollection.AddWithValue("@faxNumber", model.Fax); paramCollection.AddWithValue("@email", model.Email); paramCollection.AddWithValue("@url", model.Url); SqlParameter p = new SqlParameter("@id", System.Data.SqlDbType.Int); p.Direction = System.Data.ParameterDirection.Output; paramCollection.Add(p); }, returnParameters : delegate(SqlParameterCollection param) { int.TryParse(param["@id"].Value.ToString(), out id); }); } catch (Exception ex) { throw ex; } return(id); }
public HttpResponseMessage CompanyInsert(CompanyInsertRequest model) { if (!ModelState.IsValid) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } ItemResponse <int> response = new ItemResponse <int>(); response.Item = _CompanyService.InsertCompany(model); return(Request.CreateResponse(HttpStatusCode.OK, response)); }
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ public int BuildCompanyOnRegistration(RegisterViewModel model, string ownerId) { int companyId = 0; // Create Company Account CompanyInsertRequest company = new CompanyInsertRequest { Name = model.CompanyName, OwnerId = ownerId, TypeId = model.CompanyRole }; companyId = InsertCompany(company); return(companyId); }
public HttpResponseMessage Register(UserAddRequest model) { if (!ModelState.IsValid) { Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } ItemResponse <bool> response = new ItemResponse <bool>(); bool success = false; IdentityUser newUser = null; // Use model input to build user Account, company, and profile in DB try { // Create User Account newUser = UserService.CreateUser(model.Email, model.Password); // Determine company role CompanyRoleType companyType; switch (model.CompanyRole) { case "Buyer": companyType = CompanyRoleType.Buyer; break; case "Supplier": companyType = CompanyRoleType.Supplier; break; case "Shipper": companyType = CompanyRoleType.Shipper; break; default: throw new Exception("Unrecognized Company Role: " + model.CompanyRole); } // Create Company Account CompanyInsertRequest company = new CompanyInsertRequest { Name = model.Company, OwnerId = newUser.Id, TypeId = companyType }; int companyId = _CompanyOptionService.InsertCompany(company); // Set User Role _AdminService.SetUserRole(newUser.Id, _AdminService.GetCompanyOwnerRoleId()); //- Create Blank User Profile CreateBlankProfileRequest newUserProfile = new CreateBlankProfileRequest { UserId = newUser.Id, UserEmail = newUser.Email, CompanyId = companyId }; _UserProfileService.InsertBlankProfile(newUserProfile); } catch (Exception ex) { throw ex; } if (newUser != null) { // Use model input to create confirmation email InsertTokenRequest insertToken = new InsertTokenRequest { Email = model.Email, UserId = newUser.Id, TokenType = Enums.TokenType.Registration }; EmailRequest ToSend = new EmailRequest(); try { ToSend = _UserEmailService.BuildAccountConfirmEmail(insertToken); } catch (Exception ex) { throw ex; } _UserEmailService.SendEmail(ToSend); success = true; } response.Item = success; return(Request.CreateResponse(HttpStatusCode.OK, response)); }