public ActionResult <UserTable> Unread([FromBody] List <EmailTable> modelList) { Response response = new Response(); using (EmailDatabaseContext context = new EmailDatabaseContext()) { foreach (EmailTable model in modelList) { EmailTable emailRecordInDb = context.EmailTable.Where(eml => eml.Id == model.Id).SingleOrDefault(); if (ModelState.IsValid) { if (emailRecordInDb != null) { emailRecordInDb.IsRead = false; context.SaveChanges(); response.isOk = true; response.message = "Email is unread."; } } } } return(Content(JsonConvert.SerializeObject(response))); }
public ActionResult <EmailTable> Send([FromBody] EmailTable model) { using (EmailDatabaseContext context = new EmailDatabaseContext()) { Response response = new Response(); if (ModelState.IsValid) { context.EmailTable.Add(model); try { context.SaveChanges(); } catch (NullReferenceException ex) { response.message = ex.ToString(); response.isOk = false; return(Content(JsonConvert.SerializeObject(response))); } } response.message = "Mail sent."; response.isOk = true; return(Content(JsonConvert.SerializeObject(response))); } }
public ActionResult <UserTable> ChangePassword([FromBody] UserTable model) { Response response = new Response(); using (EmailDatabaseContext context = new EmailDatabaseContext()) { UserTable userRecordInDb = context.UserTable.Where(u => u.Email == model.Email).SingleOrDefault(); if (ModelState.IsValid) { if (userRecordInDb != null) { if (userRecordInDb.Password == model.Password) { response.isOk = false; response.message = "Password cannot be same."; } else { userRecordInDb.Password = model.Password; context.SaveChanges(); response.isOk = true; response.message = "Password for " + userRecordInDb.Email + " has been changed."; } } } } return(Content(JsonConvert.SerializeObject(response))); }
public ActionResult <UserTable> SignInPost([FromBody] UserTable model) { Response response = new Response(); using (EmailDatabaseContext context = new EmailDatabaseContext()) { UserTable userRecordInDb = context.UserTable.Where( u => u.Email == model.Email ).SingleOrDefault(); if (ModelState.IsValid) { if (userRecordInDb != null) { if (userRecordInDb.Password == model.Password) { response.id = userRecordInDb.Id; response.message = "Welcome " + userRecordInDb.Name + " " + userRecordInDb.Surname + "!"; response.isOk = true; return(Content(JsonConvert.SerializeObject(response))); } } } } response.message = "Email or password is wrong."; response.isOk = false; return(Content(JsonConvert.SerializeObject(response))); }
public ActionResult <string> Outbox(int userId) { using (EmailDatabaseContext context = new EmailDatabaseContext()) { UserTable user = context.UserTable.Where(usr => usr.Id == userId).SingleOrDefault(); List <EmailTable> mailList = context.EmailTable.Where(eml => eml.FromMail == user.Email && !(eml.IsDeleted)).ToList(); mailList.Reverse(); if (mailList != null) { string json = JsonConvert.SerializeObject(mailList); return(Content(json)); } return(Content("You do not have any outbox mails.")); } }
public ActionResult <UserTable> SignUpPost([FromBody] UserTable model) { Response response = new Response(); using (EmailDatabaseContext context = new EmailDatabaseContext()) { var userWithSameEmail = context.UserTable.Where(u => u.Email == model.Email).SingleOrDefault(); //checking if the email already exits for any user if (ModelState.IsValid) { if (userWithSameEmail == null) { context.UserTable.Add(model); try { context.SaveChanges(); } catch (NullReferenceException ex) { response.message = ex.ToString(); response.isOk = false; return(Content(JsonConvert.SerializeObject(response))); } } else { response.message = "User with this Email Already Exists."; response.isOk = false; return(Content(JsonConvert.SerializeObject(response))); } } } response.message = model.Name + " " + model.Surname + " registered succesfully."; response.isOk = true; return(Content(JsonConvert.SerializeObject(response))); }