public Boolean SendMail(string from, List<string> emailList, string subject, string bodyHtml, TForm newForm, Int32 formId, SystemUsers sentUser) { try { MailMessage completeMessage = new MailMessage(); completeMessage.From = new MailAddress(from); completeMessage.Subject = subject; completeMessage.Body = bodyHtml; completeMessage.IsBodyHtml = true; //SmtpClient client = new SmtpClient("TingleNT30.wctingle.com"); //client.UseDefaultCredentials = true; SmtpClient client = new SmtpClient("smtp.gmail.com", 587); client.Credentials = new NetworkCredential("*****@*****.**", "ZXCasdQWE123!"); client.EnableSsl = true; using (FormContext ctx = new FormContext()) { foreach (string email in emailList) { RequestNotifications newRN = new RequestNotifications { Form = ctx.TForms.FirstOrDefault(x => x.FormID == newForm.FormID), BodyHtml = bodyHtml, RequestedFormId = formId, SentBy = ctx.SystemUsers.FirstOrDefault(x => x.SystemUserID == sentUser.SystemUserID), Status = 0, Timestamp = DateTime.Now, ToEmailAddress = email }; ctx.RequestNotifications.Add(newRN); ctx.SaveChanges(); try { completeMessage.To.Clear(); completeMessage.To.Add(email); client.Send(completeMessage); newRN.Status = 1; ctx.SaveChanges(); } catch(Exception exc) {} } } return true; } catch (Exception ex) { return false; //throw ex; } }
public Boolean SendInventoryNotification(List<string> emailList, string bodyHtml, SystemUsers sentUser) { try { MailMessage completeMessage = new MailMessage(); completeMessage.From = new MailAddress("*****@*****.**"); completeMessage.Subject = "Inventory Approval Notification"; completeMessage.Body = bodyHtml; completeMessage.IsBodyHtml = true; //SmtpClient client = new SmtpClient("TingleNT30.wctingle.com"); //client.UseDefaultCredentials = true; SmtpClient client = new SmtpClient("smtp.gmail.com", 587); client.Credentials = new NetworkCredential("*****@*****.**", "ZXCasdQWE123!"); client.EnableSsl = true; using (FormContext ctx = new FormContext()) { foreach (string email in emailList) { InventoryApprovalNotifications newRN = new InventoryApprovalNotifications { BodyHtml = bodyHtml, SentBy = ctx.SystemUsers.FirstOrDefault(x => x.SystemUserID == sentUser.SystemUserID), Status = 0, Timestamp = DateTime.Now, ToEmailAddress = email }; ctx.InventoryApprovalNotifications.Add(newRN); ctx.SaveChanges(); try { completeMessage.To.Clear(); completeMessage.To.Add(email); client.Send(completeMessage); newRN.Status = 1; ctx.SaveChanges(); } catch (Exception exc) { } } } return true; } catch (Exception ex) { return false; } }
public bool HasAccess(SystemUsers user, string formName) { try { using (FormContext ctx = new FormContext()) { return ctx.FormPermissions.Any(x => x.Enabled == true && x.FormName == formName && x.UserRole.UserRoleId == user.UserRole.UserRoleId); } } catch (Exception ex) { return false; } }
public bool HasBeenAssigned(SystemUsers user, Int32 formId, string formName) { try { using (FormContext context = new FormContext()) { return context.UserAssignments.Any(x => x.User.SystemUserID == user.SystemUserID && x.RelatedFormId == formId && x.Form.FormName == formName); } } catch (Exception ex) { return false; } }
public void fvUserInsert_InsertItem() { try { TextBox txtUserNameInsert = (TextBox)fvUserInsert.FindControl("txtUserNameInsert"); TextBox txtDisplayNameInsert = (TextBox)fvUserInsert.FindControl("txtDisplayNameInsert"); TextBox txtEmailAddressInsert = (TextBox)fvUserInsert.FindControl("txtEmailAddressInsert"); RadioButtonList rblUserStatusInsert = (RadioButtonList)fvUserInsert.FindControl("rblUserStatusInsert"); CheckBox cbInventoryApproval = (CheckBox)fvUserInsert.FindControl("cbInventoryApproval"); int roleId = Convert.ToInt32(((DropDownList)fvUserInsert.FindControl("ddlUserRoleInsert")).SelectedValue); Int16 status = Convert.ToInt16(rblUserStatusInsert.SelectedValue); using (FormContext ctx = new FormContext()) { if (ctx.SystemUsers.Where(su => su.UserName == txtUserNameInsert.Text).FirstOrDefault() == null) { SystemUsers newUser = new SystemUsers(); UserRoles newRole = ctx.UserRoles.Where(ur => ur.UserRoleId == roleId).FirstOrDefault(); newUser.UserName = txtUserNameInsert.Text; newUser.DisplayName = txtDisplayNameInsert.Text; newUser.EmailAddress = txtEmailAddressInsert.Text; newUser.Status = status; newUser.UserRole = newRole; newUser.InventoryApprovalUser = cbInventoryApproval.Checked; ctx.SystemUsers.Add(newUser); if (ModelState.IsValid) { ctx.SaveChanges(); gvUsers.DataBind(); } lblUserMessage.Text = ""; } else { lblUserMessage.Text = "A User with the username: "******" already exists."; } } } catch (Exception ex) { lblUserMessage.Text = "Unable to add new User. Please contact your system administrator."; } }