public HttpResponseMessage CreateTenant(HttpRequestMessage request, TenantViewModel tenant) { return(CreateHttpResponse(request, () => { HttpResponseMessage response = null; if (!ModelState.IsValid) { response = request.CreateResponse(HttpStatusCode.BadRequest, new { success = false }); } else { var existingTenant = _tenantRepository.GetAll().FirstOrDefault(x => x.tenant_name == tenant.tenant_name || x.email == tenant.email); GlobalVars.gvTenantKey = tenant.tenant_key; if (existingTenant != null) { if (existingTenant.email == tenant.email) { throw new Exception("Email is already Exist!"); } else { throw new Exception("Tenant is already Exist!"); } } _membershipService.CreateTenant(tenant.tenant_key, tenant.tenant_name, tenant.tenant_type, tenant.contact_person, tenant.email, tenant.contact_no, tenant.alt_contact_no, tenant.tenant_key, new int[] { 1 }, tenant.account_valid_till); _membershipService.Assignmenu(tenant.tenant_key); string vSubject = "Welcome to Projects Automation!"; string vBody = File.ReadAllText(HttpContext.Current.Server.MapPath("~") + "/Templates/Email/tenant_registration_email.html"); vBody = vBody.Replace("!Tenant", tenant.contact_person.ToString()); vBody = vBody.Replace("!uid", tenant.tenant_key.ToString()); vBody = vBody.Replace("!pwd", tenant.tenant_key.ToString()); Library.Email vEmail = new Library.Email(); bool emailsent = vEmail.SendMail(tenant.email, Convert.ToString(ConfigurationManager.AppSettings["FromEmail"]), "Projects Automation", Convert.ToString(ConfigurationManager.AppSettings["CCEmail"]), vSubject, vBody); response = request.CreateResponse(HttpStatusCode.OK, new { success = true }); } return response; })); }
public HttpResponseMessage Register(HttpRequestMessage request, UsersRegistrationViewModel user) { return(CreateHttpResponse(request, () => { HttpResponseMessage response = null; if (!ModelState.IsValid) { response = request.CreateResponse(HttpStatusCode.BadRequest, new { success = false }); } else { tbl_user _user = _membershipService.CreateUser(user.tenant_id, user.userid, user.UserName, user.Email, user.password, new int[] { user.Roleid }, user.is_tenant); string toMailList = null; string tomailtocc = null; if (_user != null) { //List<string> toMailList = new List<string>{ }; GlobalVars.gvUserID = _user.id; GlobalVars.gvUserName = _user.user_name; if (user.mail2tenant) { //toMailList.Add(GlobalVars.gvTenantEmail); toMailList = GlobalVars.gvTenantEmail; } if (user.mail2user) { //toMailList.Add(user.Email); // toMailList = toMailList.ToString() + "," + user.Email.ToString(); toMailList = user.Email; tomailtocc = GlobalVars.gvTenantEmail; } if (toMailList != null) { string vSubject = "Welcome to Projects!"; string vBody = File.ReadAllText(HttpContext.Current.Server.MapPath("~") + "/Templates/Email/user_registration_email.html"); vBody = vBody.Replace("!User", GlobalVars.gvUserName.ToString()); vBody = vBody.Replace("!uid", user.userid.ToString()); vBody = vBody.Replace("!pwd", user.password.ToString()); Library.Email tapCloudsEmail = new Library.Email(); // bool emailsent = vEmail.SendMail(toMailList, Convert.ToString(ConfigurationManager.AppSettings["FromEmail"]), "ICD", tomailtocc, vSubject, vBody); bool emailsent = tapCloudsEmail.SendMail(toMailList, Convert.ToString(ConfigurationManager.AppSettings["FromEmail"]), "Projects", tomailtocc, vSubject, vBody); } response = request.CreateResponse(HttpStatusCode.OK, new { success = true }); } else { response = request.CreateResponse(HttpStatusCode.OK, new { success = false }); } } return response; })); }