public string SendRegisteredData(User user) { List <string> errors = new List <string>(); if (user.Email == null) { errors.Add("no_email"); } else if (!IsValidEmail(user.Email)) { errors.Add("invalid_email"); } else if (_userRepo.FindUser(a => a.Email == user.Email) != null) { errors.Add("existing_email"); } if (user.Password == null || user.ConfirmPassword == null) { errors.Add("no_password"); } else if (user.ConfirmPassword != user.Password) { errors.Add("password_not_match"); } if (user.CompanyName == null) { errors.Add("companyname_required"); } if (user.FirstName == null) { errors.Add("firstname_required"); } else if (user.FirstName.Any(char.IsDigit)) { errors.Add("firstname_not_letter"); } else if (user.FirstName.Length > 50) { errors.Add("firstname_max_letter"); } if (user.LastName == null) { errors.Add("lastname_required"); } else if (user.LastName.Any(char.IsDigit)) { errors.Add("lastname_not_letter"); } else if (user.LastName.Length > 50) { errors.Add("lastname_max_letter"); } if (user.Phonenumber == null) { errors.Add("phone_required"); } else if (!user.Phonenumber.Any(char.IsDigit)) { errors.Add("number_only"); } if (user.Address == null) { errors.Add("address_required"); } if (user.Image == null) { errors.Add("no_picture"); } if (errors.Count != 0) { string errorList = string.Join(",", errors); return(errorList); } if (user.Image != null) { string uploadsFolder = Path.Combine(_hostingEnvironment.WebRootPath, "Images"); var uniqueName = Guid.NewGuid().ToString() + "_" + user.Image.FileName; string filePath = Path.Combine(uploadsFolder, uniqueName); user.Image.CopyTo(new FileStream(filePath, FileMode.Create)); user.ImageName = uniqueName; HttpContext.Session.SetString("Image", user.ImageName); } Utilities util = new Utilities(); user.Password = util.base64Encode(user.Password); if (_userRepo.FindUser(a => a.Email == user.Email) == null) { _userRepo.Create(user); } try { EmailClass.GmailUsername = "******"; EmailClass.GmailPassword = "******"; EmailClass mailer = new EmailClass(); mailer.ToEmail = user.Email; mailer.Subject = "You are now part of Mail Expert Messengerial"; mailer.Body += "Hi " + user.FirstName + " " + user.LastName; mailer.Body += "<br> Here's your username : "******"<br> Here's your password : "******"<br> Click here to activate your account. https://localhost:44379/User/EmailActivate/" + user.UserID; mailer.IsHtml = true; mailer.Send(); } catch (Exception e) { } return(""); }
/// <summary> /// Send Mail /// </summary> private void SendMail(XmlReader emailContent,string host,string port, string emailAddressFrom, string replyToAddress, string replyToName, string ccToAddress) { EmailClass emailClass = new EmailClass(emailContent); string subject = string.Empty; string message = string.Empty; ArrayList attachments; System.Collections.ArrayList addresses = new ArrayList(); System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient(); System.Net.Mail.MailMessage m = new System.Net.Mail.MailMessage(); //content mail get from emailContent client.Host = host; client.Port = int.Parse(port); //From MailAddressCollection mailAddressFrom = emailClass.From; mailAddressFrom.Add(emailAddressFrom); if (mailAddressFrom.Count > 0) { foreach (MailAddress mailAddress in mailAddressFrom) { m.From = ConvertDomainMail(mailAddress); break; } } //To MailAddressCollection mailAddressTo = emailClass.To; if (mailAddressTo.Count > 0) { foreach (MailAddress mailAddress in mailAddressTo) { m.To.Add(ConvertDomainMail(mailAddress)); } } //CC MailAddressCollection mailAddressCC = emailClass.CC; if (mailAddressCC.Count > 0) { foreach (MailAddress mailAddress in mailAddressCC) { m.CC.Add(ConvertDomainMail(mailAddress)); } } // Add cc method parameter if (!string.IsNullOrEmpty(ccToAddress)) { m.CC.Add(ConvertDomainMail(new MailAddress(ccToAddress))); } //BCC MailAddressCollection mailAddressBCC = emailClass.BCC; if (mailAddressBCC.Count > 0) { foreach (MailAddress mailAddress in mailAddressBCC) { m.Bcc.Add(ConvertDomainMail(mailAddress)); } } //ReplyToList MailAddressCollection mailAddressReplyTo = emailClass.ReplyTo; if (mailAddressReplyTo.Count > 0) { foreach (MailAddress mailAddress in mailAddressReplyTo) { m.ReplyToList.Add(ConvertDomainMail(mailAddress)); } } // Add sender method parameter if (!string.IsNullOrEmpty(replyToAddress)) { MailAddress senderAddress = new MailAddress(replyToAddress, replyToName); m.Sender = ConvertDomainMail(senderAddress); } m.Subject = emailClass.Subject; //Body if (!string.IsNullOrEmpty(emailClass.TextBody)) { //TextBody m.Body = emailClass.TextBody; m.IsBodyHtml = false; } else { //HtmlBody m.Body = emailClass.HtmlBody; m.IsBodyHtml = true; } //Attachments attachments = emailClass.Attachments; foreach (string attach in attachments) { Attachment attached = new Attachment(attach, MediaTypeNames.Application.Octet); m.Attachments.Add(attached); } client.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials; client.Send(m); }
public ActionResult RefreshDisbursement(IEnumerable <int> disbId, IList <int> disbItemId, IList <int> qtyDisbursed) { /* if (Session["IdEmployee"] == null || (String)Session["Role"] != "StockClerk") * return RedirectToAction("Login", "Home");*/ int IdStoreClerk = 1; if (Session["IdEmployee"] != null) { IdStoreClerk = (int)Session["IdEmployee"]; } Disbursement targetDisbursement = _disbursementDAO.FindById(disbId.First()); ViewBag.disb = targetDisbursement; List <DisbursementItem> targetList = targetDisbursement.DisbursementItems.ToList(); Employee sup = _employeeDAO.FindByRole(7).FirstOrDefault(); Employee man = _employeeDAO.FindByRole(6).FirstOrDefault(); // if qtyDisbursed < disbItem.UnitIssued then raise a SA-broken and a reversal entry to qtyDisbursed for (int i = 0; i < targetList.Count; i++) { if (qtyDisbursed[i] < targetList[i].UnitIssued) { _stockRecordDAO.StockAdjustmentDuringDisbursement(qtyDisbursed[i], targetList[i], IdStoreClerk); // reverses the amount disbursed to the department // commented out as net = 0 diff //_itemDAO.UpdateUnits(targetList[i].Item, -(targetList[i].UnitIssued - qtyDisbursed[i])); //_itemDAO.UpdateUnits(targetList[i].Item, (targetList[i].UnitIssued - qtyDisbursed[i])); // sends a notification to either supervisor or manager on stock record's value #region Send notification String message = $"Stock adjustment raised for Item ({targetList[i].Item.Description}). Please approve/reject."; int notifId = _notificationDAO.CreateNotification(message); var hub = GlobalHost.ConnectionManager.GetHubContext <ChatHub>(); SupplierItem si = _supplierItemDAO.FindByItem(targetList[i].Item); if (Math.Abs((targetList[i].UnitIssued - qtyDisbursed[i]) * si.Price) >= 250) { _notificationChannelDAO.SendNotification(IdStoreClerk, man.IdEmployee, notifId, DateTime.Now); hub.Clients.All.receiveNotification(man.IdEmployee); EmailClass emailClass = new EmailClass(); emailClass.SendTo(man.Email, "SSIS System Email", message); } else { _notificationChannelDAO.SendNotification(IdStoreClerk, sup.IdEmployee, notifId, DateTime.Now); hub.Clients.All.receiveNotification(sup.IdEmployee); EmailClass emailClass = new EmailClass(); emailClass.SendTo(sup.Email, "SSIS System Email", message); } #endregion } } // updates the disbitemId's unitissued to the qtyDisbursed _disbursementItemDAO.UpdateUnitIssued(disbItemId, qtyDisbursed); return(RedirectToAction("Disbursement")); }
public ActionResult CreateTicket(HttpPostedFileBase file, TicketPost requestPost) { if (!ModelState.IsValid) { var message = string.Join(" | ", ModelState.Values .SelectMany(v => v.Errors) .Select(e => e.ErrorMessage)); Session["Error"] = message; return(RedirectToAction("Ticket")); } //save ticket Ticket ticketParam = new Ticket(); ticketParam.Title = requestPost.Title; ticketParam.Message = requestPost.Message; ticketParam.TicketId = RandomNumber() + RandomNumber(); ticketParam.Id = ticketParam.TicketId; ticketParam.SourceData = requestPost.type; ticketParam.Ticket_Status = 1; ticketParam.IGR_Code = Session["igr"].ToString(); ticketParam.Created_at = DateTime.Now; ticketParam.AdmissionNo = Session["AdmissionNo"].ToString(); string name = Session["name"].ToString(); try { var ticketPara = db.Ticket.Add(ticketParam); db.SaveChanges(); if (ticketPara != null) { EmailParam param = new EmailParam(); param.Email = "*****@*****.**"; param.SenderEmail = "*****@*****.**"; param.From = "Open Ticket for IGR"; param.Message = "Hi Admin,\n\nYou have a pending ticket with content below\n\nPlease login into support to respond ticket\n\n--------------\n\n" + requestPost.Message + "\n\n------------\n\nSender Name: " + name + "\nAmissionNo: " + ticketParam.AdmissionNo; EmailClass.sendEmail(EMAILAPI, param); } } catch (Exception ex) { Session["Error"] = ex.Message.ToString(); return(RedirectToAction("Ticket")); } foreach (string upload in Request.Files) { if (Request.Files[upload].ContentLength > 0) { var filename = ticketParam.TicketId + ".png"; var size = Request.Files[upload].ContentLength; if (size > 532000) { Session["Error"] = "File cannot be larger than 500KB"; return(RedirectToAction("Ticket")); } var FileExt = Request.Files[upload].ContentType; if (FileExt == "image/png" || FileExt == "image/jpeg") { var filePathOriginal = Server.MapPath("/Content/ticket"); var filePathThumbnail = Server.MapPath("/Content/ticket"); string savedFileName = Path.Combine(filePathOriginal, filename); Request.Files[upload].SaveAs(savedFileName); } else { Session["Error"] = "Please upload a .png or .jpeg format"; return(RedirectToAction("Ticket")); } } } Session["Sucess"] = "Ticket successfully opened"; return(RedirectToAction("Ticket")); }
public ActionResult GetChangeRepCP(string emp, string cp, string judge) { string submit = judge; string location = cp; string empName = emp; if (judge.Equals("Cancel")) { RedirectToAction("CurrentRepCP", "DepartmentActingHead"); } else if (judge.Equals("Apply Change")) { if (location != null && empName != null) { Employee newRep = _employeeDAO.FindEmployeeByName(empName); string codeDepartment = newRep.CodeDepartment; string oldCollectionPoint = _collectionPointDAO.FindByDepartment(codeDepartment); Employee oldRep = _employeeDAO.FindDepartmentRep(codeDepartment); if (oldRep == null) { //if there is no oldRep then do not need to set idrole etc //but need set new rep _employeeDAO.ChangeNewRepCP(newRep.Name, location); //@Shutong: send notification here Employee e = _employeeDAO.FindEmployeeByName(newRep.Name); int IdEmployee = e.IdEmployee; var hub = GlobalHost.ConnectionManager.GetHubContext <ChatHub>(); hub.Clients.All.receiveNotification(IdEmployee); EmailClass emailClass = new EmailClass(); string message = "Hi " + newRep.Name + ", you are appointed as Department Rep. Collection Point is " + location; _notificationChannelDAO.CreateNotificationsToIndividual(IdEmployee, (int)Session["IdEmployee"], message); emailClass.SendTo(_employeeDAO.FindEmployeeById(IdEmployee).Email, "SSIS System Email", message); //end of notification sending } else { // old rep is not null //change old rep back to employee //change the current employee to rep and change collection point _employeeDAO.PutOldRepBack(oldRep.Name); _employeeDAO.ChangeNewRepCP(newRep.Name, location); if (newRep.Name != oldRep.Name) { //@Shutong: send notification here int IdEmployee = oldRep.IdEmployee; var hub = GlobalHost.ConnectionManager.GetHubContext <ChatHub>(); hub.Clients.All.receiveNotification(IdEmployee); EmailClass emailClass = new EmailClass(); string message = "Hi " + oldRep.Name + ", you are not Department Rep anymore."; _notificationChannelDAO.CreateNotificationsToIndividual(IdEmployee, (int)Session["IdEmployee"], message); emailClass.SendTo(oldRep.Email, "SSIS System Email", message); IdEmployee = newRep.IdEmployee; hub.Clients.All.receiveNotification(IdEmployee); message = "Hi " + newRep.Name + ", you are appointed as Department Rep. Collection Point is " + location; _notificationChannelDAO.CreateNotificationsToIndividual(IdEmployee, (int)Session["IdEmployee"], message); emailClass.SendTo(newRep.Email, "SSIS System Email", message); //end of notification sending } //if rep didnot change but only cp changes else { if (oldCollectionPoint != location) { int IdEmployee = oldRep.IdEmployee; var hub = GlobalHost.ConnectionManager.GetHubContext <ChatHub>(); hub.Clients.All.receiveNotification(IdEmployee); EmailClass emailClass = new EmailClass(); string message = "Hi " + oldRep.Name + ", your collection point has been changed by your head."; _notificationChannelDAO.CreateNotificationsToIndividual(IdEmployee, (int)Session["IdEmployee"], message); emailClass.SendTo(oldRep.Email, "SSIS System Email", message); } } } return(RedirectToAction("CurrentRepCP", "DepartmentActingHead")); } //if (location != null && empName != null) //{ // Employee newRep = _employeeDAO.FindEmployeeByName(empName); // string codeDepartment = newRep.CodeDepartment; // string oldCollectionPoint = _collectionPointDAO.FindByDepartment(codeDepartment); // Employee oldRep = _employeeDAO.FindDepartmentRep(codeDepartment); // //change old rep to employee // _employeeDAO.PutOldRepBack(oldRep.Name); // _employeeDAO.ChangeNewRepCP(newRep.Name, location); // if (newRep.Name != oldRep.Name) // { // //@Shutong: send notification here // int IdEmployee = oldRep.IdEmployee; // var hub = GlobalHost.ConnectionManager.GetHubContext<ChatHub>(); // hub.Clients.All.receiveNotification(IdEmployee); // EmailClass emailClass = new EmailClass(); // string message = "Hi " + oldRep.Name // + ", you are not Department Rep anymore."; // _notificationChannelDAO.CreateNotificationsToIndividual(IdEmployee, (int)Session["IdEmployee"], message); // emailClass.SendTo(oldRep.Email, "SSIS System Email", message); // IdEmployee = newRep.IdEmployee; // hub.Clients.All.receiveNotification(IdEmployee); // message = "Hi " + newRep.Name // + ", you are appointed as Department Rep."; // _notificationChannelDAO.CreateNotificationsToIndividual(IdEmployee, (int)Session["IdEmployee"], message); // emailClass.SendTo(newRep.Email, "SSIS System Email", message); // //end of notification sending // } // //if rep didnot change but only cp changes // else // { // if (oldCollectionPoint != location) // { // int IdEmployee = oldRep.IdEmployee; // var hub = GlobalHost.ConnectionManager.GetHubContext<ChatHub>(); // hub.Clients.All.receiveNotification(IdEmployee); // EmailClass emailClass = new EmailClass(); // string message = "Hi " + oldRep.Name // + ", your collection point has been changed by your head."; // _notificationChannelDAO.CreateNotificationsToIndividual(IdEmployee, (int)Session["IdEmployee"], message); // emailClass.SendTo(oldRep.Email, "SSIS System Email", message); // } // } // //end of notification sending // return RedirectToAction("CurrentRepCP", "DepartmentActingHead"); //} } return(RedirectToAction("CurrentRepCP", "DepartmentActingHead")); }
protected void txtEmail_TextChanged(object sender, EventArgs e) { ddlEmailProvider.SelectedValue = EmailClass.getProviderName(txtEmail.Text); }
protected void btnSubmit_Click(object sender, EventArgs e) { string email = txtEmail.Text; string password = txtPassword.Text; int abc = ddlEmailProvider.SelectedIndex; if (Session["tempEmail"] != null) { EmailClass emailClass = (EmailClass)Session["tempEmail"]; try { EmailCredential emailCredential = new EmailCredential(new NetworkCredential(email, password), EmailClass.getStmpClient(ddlEmailProvider.SelectedValue)); emailClass.sendEmail(emailCredential); EmailClass.generateCredential(email, password, EmailClass.getStmpClient(ddlEmailProvider.SelectedValue)); string url = Request.QueryString["ReturnUrl"]; Response.Write(" <script language = 'javascript'> window.alert('Email has been sent. Redirecting previous page.'); window.location = '" + url + "';</script>"); } catch (SmtpFailedRecipientsException stmpRecipientsException) { lblError.Text = "Email failed to send to " + stmpRecipientsException.FailedRecipient; } catch (SmtpException smtpException) { lblError.Text = "The email or password might typed wrong or " + smtpException.Message; } } else { lblError.Text = "There is no email to be send, credential is not created."; } }