public IHttpActionResult Inbox(SentAdminMessageModel sentmodel) { int admin_id = 1; var fileImage = sentmodel.MessageImage; byte[] img; if (fileImage != null) { img = fileImage; } else { img = null; } // var userId = Convert.ToInt32(Session["LogedUserID"].ToString()); SleepingPartnermanagementTestingEntities db = new SleepingPartnermanagementTestingEntities(); SentAdminMessage sent_msg = new SentAdminMessage(); sent_msg.Sender = sentmodel.Sender = sentmodel.UserId; sent_msg.UserId = sentmodel.UserId = sentmodel.UserId; sent_msg.SponserId = admin_id; sent_msg.Sender_Name = sentmodel.Sender_Name; sent_msg.Message = sentmodel.Message; sent_msg.IsRead = sentmodel.IsRead = false; sent_msg.CreateDate = sentmodel.CreateDate = DateTime.Today; sent_msg.MessageImage = img; //sent_msg.MessageImage = fileImage.InputStream; //imageByte; db.SentAdminMessages.Add(sent_msg); //db.SaveChanges(); ReceiveAdminMessage Recive_msg = new ReceiveAdminMessage(); Recive_msg.Sender = sentmodel.Sender = sentmodel.UserId; Recive_msg.UserId = sentmodel.UserId = sentmodel.UserId; Recive_msg.SponserId = admin_id; Recive_msg.Sender_Name = sentmodel.Sender_Name; Recive_msg.Message = sentmodel.Message; Recive_msg.IsRead = sentmodel.IsRead = true; Recive_msg.CreateDate = sentmodel.CreateDate = DateTime.Today; Recive_msg.MessageImage = img; db.ReceiveAdminMessages.Add(Recive_msg); db.SaveChanges(); //var fcm = db.NewUserRegistrations.Where(x => x.UserId == sentmodel.SponserId).Select(x => x.Fcm).FirstOrDefault(); //if (fcm != null) //{ // WebClient client = new WebClient(); // client.DownloadString("https://sleepingpartnertesting.royalcryptoexchange.com/messageNotifyApi.php?send_notification&sname=" + // sentmodel.Sender_Name + "&uid=" + sentmodel.UserId + "&sid=" + sentmodel.SponserId + "&message=" + sentmodel.Message // + "&token=" + fcm); //} return(Ok(new { success = true, message = "messsage sent successfully" })); }
public IHttpActionResult DeleteReadMessage(int Id) { try { SleepingPartnermanagementTestingEntities db = new SleepingPartnermanagementTestingEntities(); SentAdminMessage sdm = db.SentAdminMessages.Where(x => x.Id == Id).FirstOrDefault <SentAdminMessage>(); db.SentAdminMessages.Remove(sdm); //d.Id = Id; //db.Entry(d).State = System.Data.EntityState.Deleted; db.SaveChanges(); return(Ok(new { success = true, message = "message delete successfully" })); } catch (Exception ex) { return(Ok(new { success = true, message = "unable to delete this field", ex.Message })); } }