Beispiel #1
0
 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));
         }
     }
 }
Beispiel #2
0
        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));
                }
            }
        }