public HttpResponseMessage addEmail([FromBody] MailData mailData) { using (FutureMeProductEntities ctx = new FutureMeProductEntities()) { try { var id = ctx.USERS.Where(x => x.Email == mailData.userEmail).FirstOrDefault().ID; if (id == null) { return Request.CreateResponse(HttpStatusCode.BadRequest); } MAIL mail = new MAIL(); mail.IDUser = id; mail.EmailTo = mailData.EmailTo; mail.Subject = mailData.Subject; mail.Letter = mailData.Letter; mail.DeliverOn = mailData.DeliverOn; mail.Status = 0; // Store mail, not send yet mail.ViewStatus = mailData.ViewStatus; ctx.MAILs.Add(mail); ctx.SaveChanges(); return Request.CreateResponse(HttpStatusCode.OK); } catch (Exception e) { return Request.CreateResponse(HttpStatusCode.BadRequest, e); } } }
public HttpResponseMessage UpdateSV([FromBody] int userid, [FromBody] MAIL mailData) { using (FutureMeProductEntities ctx = new FutureMeProductEntities()) { int mailid = mailData.ID; var mail = ctx.MAILs.Where(x => x.IDUser == userid && x.ID == mailid).FirstOrDefault(); if (mail == null) { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } // Check status if (mail.ViewStatus == 1 && mail.Status == 0) { mail.EmailTo = mailData.EmailTo; mail.Subject = mailData.Subject; mail.Letter = mailData.Letter; mail.DeliverOn = mailData.DeliverOn; int affected = ctx.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK, affected)); } else { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } } }
public HttpResponseMessage addEmail([FromBody] MailData mailData) { using (FutureMeProductEntities ctx = new FutureMeProductEntities()) { try { var id = ctx.USERS.Where(x => x.Email == mailData.userEmail).FirstOrDefault().ID; if (id == null) { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } MAIL mail = new MAIL(); mail.IDUser = id; mail.EmailTo = mailData.EmailTo; mail.Subject = mailData.Subject; mail.Letter = mailData.Letter; mail.DeliverOn = mailData.DeliverOn; mail.Status = 0; // Store mail, not send yet mail.ViewStatus = mailData.ViewStatus; ctx.MAILs.Add(mail); ctx.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK)); } catch (Exception e) { return(Request.CreateResponse(HttpStatusCode.BadRequest, e)); } } }
public HttpResponseMessage updateMail([FromBody] MailData mailData) { using (FutureMeProductEntities ctx = new FutureMeProductEntities()) { var id = ctx.USERS.Where(x => x.Email == mailData.userEmail).FirstOrDefault().ID; if (id == null) { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } var mail = ctx.MAILs.Where(x => x.IDUser == id && x.ID == mailData.ID).FirstOrDefault(); if (mail == null) { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } if (mail.ViewStatus == 1 && mail.Status == 0) { mail.EmailTo = mailData.EmailTo; mail.Subject = mailData.Subject; mail.Letter = mailData.Letter; mail.DeliverOn = mailData.DeliverOn; mail.ViewStatus = mailData.ViewStatus; int affected = ctx.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK, affected)); } else { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } } }
public void CacheItemRemoved(string k, object v, CacheItemRemovedReason r) { // do stuff here if it matches our taskname, like WebRequest // re-add our task so it recurs using (FutureMeProductEntities ctx = new FutureMeProductEntities()) { try { DateTime now = DateTime.Now.Date; var ListMailsNotSend = ctx.MAILs.Where(x => x.Status == 0 && DbFunctions.TruncateTime(x.DeliverOn) == now).ToList(); if (ListMailsNotSend == null) { return; } SmtpClient mySmtpClient = new SmtpClient(); MailAddress from = new MailAddress("*****@*****.**", "Send2Future"); foreach(MAIL mail in ListMailsNotSend) { int status = mail.Status; // = 0 try { MailMessage email = new MailMessage(); email.From = from; email.To.Add(mail.EmailTo.Trim()); email.Subject = mail.Subject.Trim(); email.SubjectEncoding = System.Text.Encoding.UTF8; // set body-message and encoding email.Body = mail.Letter.Trim(); email.BodyEncoding = System.Text.Encoding.UTF8; // text or html email.IsBodyHtml = true; mySmtpClient.Send(email); status = 1; // send } catch (SmtpException ex) { status = 3; // send error //throw new ApplicationException("SmtpException has occured: " + ex.Message); } mail.Status = status; int affected = ctx.SaveChanges(); } } catch (Exception ex) { //throw ex; } } AddTask(k, Convert.ToInt32(v)); }
public HttpResponseMessage updatePassword([FromBody] USER UserData) { using (FutureMeProductEntities ctx = new FutureMeProductEntities()) { var user = ctx.USERS.Where(x => x.ID == UserData.ID).FirstOrDefault(); if (user == null) { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } user.Password = UserData.Password; int affected = ctx.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK, affected)); } }
public HttpResponseMessage deleteMail([FromBody] MAIL mail) { using (FutureMeProductEntities ctx = new FutureMeProductEntities()) { var rs = ctx.MAILs.Where(x => x.IDUser == mail.IDUser && x.ID == mail.ID).FirstOrDefault(); if (rs == null) { return Request.CreateResponse(HttpStatusCode.BadRequest); } ctx.MAILs.Remove(rs); int affected = ctx.SaveChanges(); return Request.CreateResponse(HttpStatusCode.OK, affected); } }
public HttpResponseMessage googleSignIn([FromBody] USER userData) { var request = (HttpWebRequest)WebRequest.Create("https://www.googleapis.com/oauth2/v3/tokeninfo?id_token=" + userData.Password); try { using (WebResponse response = request.GetResponse()) { using (FutureMeProductEntities ctx = new FutureMeProductEntities()) { if (userData == null) { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } var user = ctx.USERS.Where(x => x.Email == userData.Email).FirstOrDefault(); if (user == null) { try { USER u = new USER(); u.Email = userData.Email; u.Password = userData.Password.Substring(0, 16); ctx.USERS.Add(u); ctx.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK)); } catch (Exception e) { return(Request.CreateResponse(HttpStatusCode.BadRequest, e)); } } else { var returnUser = new USER(); returnUser.Email = user.Email; returnUser.ID = user.ID; return(Request.CreateResponse(HttpStatusCode.OK, returnUser)); } } } } catch (WebException e) { return(Request.CreateResponse(HttpStatusCode.BadRequest, e)); } }
public HttpResponseMessage deleteMail([FromBody] MAIL mail) { using (FutureMeProductEntities ctx = new FutureMeProductEntities()) { var rs = ctx.MAILs.Where(x => x.IDUser == mail.IDUser && x.ID == mail.ID).FirstOrDefault(); if (rs == null) { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } ctx.MAILs.Remove(rs); int affected = ctx.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK, affected)); } }
public HttpResponseMessage addUser([FromBody] USER UserData) { using (FutureMeProductEntities ctx = new FutureMeProductEntities()) { try { USER user = new USER(); user.Email = UserData.Email; user.Password = UserData.Password; ctx.USERS.Add(user); ctx.SaveChanges(); return Request.CreateResponse(HttpStatusCode.OK); } catch (Exception e) { return Request.CreateResponse(HttpStatusCode.BadRequest, e); } } }
public HttpResponseMessage addUser([FromBody] USER UserData) { using (FutureMeProductEntities ctx = new FutureMeProductEntities()) { try { USER user = new USER(); user.Email = UserData.Email; user.Password = UserData.Password; ctx.USERS.Add(user); ctx.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK)); } catch (Exception e) { return(Request.CreateResponse(HttpStatusCode.BadRequest, e)); } } }
public HttpResponseMessage UpdateSV([FromBody] int userid, [FromBody] MAIL mailData) { using (FutureMeProductEntities ctx = new FutureMeProductEntities()) { int mailid = mailData.ID; var mail = ctx.MAILs.Where(x => x.IDUser == userid && x.ID == mailid).FirstOrDefault(); if (mail == null) { return Request.CreateResponse(HttpStatusCode.BadRequest); } // Check status if (mail.ViewStatus == 1 && mail.Status == 0) { mail.EmailTo = mailData.EmailTo; mail.Subject = mailData.Subject; mail.Letter = mailData.Letter; mail.DeliverOn = mailData.DeliverOn; int affected = ctx.SaveChanges(); return Request.CreateResponse(HttpStatusCode.OK, affected); } else { return Request.CreateResponse(HttpStatusCode.BadRequest); } } }
public HttpResponseMessage updatePassword([FromBody] USER UserData) { using (FutureMeProductEntities ctx = new FutureMeProductEntities()) { var user = ctx.USERS.Where(x => x.ID == UserData.ID).FirstOrDefault(); if (user == null) { return Request.CreateResponse(HttpStatusCode.BadRequest); } user.Password = UserData.Password; int affected = ctx.SaveChanges(); return Request.CreateResponse(HttpStatusCode.OK, affected); } }
public HttpResponseMessage updateMail([FromBody] MailData mailData) { using (FutureMeProductEntities ctx = new FutureMeProductEntities()) { var id = ctx.USERS.Where(x => x.Email == mailData.userEmail).FirstOrDefault().ID; if (id == null) { return Request.CreateResponse(HttpStatusCode.BadRequest); } var mail = ctx.MAILs.Where(x => x.IDUser == id && x.ID == mailData.ID).FirstOrDefault(); if (mail == null) { return Request.CreateResponse(HttpStatusCode.BadRequest); } if (mail.ViewStatus == 1 && mail.Status == 0) { mail.EmailTo = mailData.EmailTo; mail.Subject = mailData.Subject; mail.Letter = mailData.Letter; mail.DeliverOn = mailData.DeliverOn; mail.ViewStatus = mailData.ViewStatus; int affected = ctx.SaveChanges(); return Request.CreateResponse(HttpStatusCode.OK, affected); } else { return Request.CreateResponse(HttpStatusCode.BadRequest); } } }
public HttpResponseMessage googleSignIn([FromBody] USER userData) { var request = (HttpWebRequest)WebRequest.Create("https://www.googleapis.com/oauth2/v3/tokeninfo?id_token=" + userData.Password); try { using (WebResponse response = request.GetResponse()) { using (FutureMeProductEntities ctx = new FutureMeProductEntities()) { if (userData == null) return Request.CreateResponse(HttpStatusCode.BadRequest); var user = ctx.USERS.Where(x => x.Email == userData.Email).FirstOrDefault(); if (user == null) { try { USER u = new USER(); u.Email = userData.Email; u.Password = userData.Password.Substring(0, 16); ctx.USERS.Add(u); ctx.SaveChanges(); return Request.CreateResponse(HttpStatusCode.OK); } catch (Exception e) { return Request.CreateResponse(HttpStatusCode.BadRequest, e); } } else { var returnUser = new USER(); returnUser.Email = user.Email; returnUser.ID = user.ID; return Request.CreateResponse(HttpStatusCode.OK, returnUser); } } } } catch (WebException e) { return Request.CreateResponse(HttpStatusCode.BadRequest, e); } }