public ActionResult ProgramDetail(int id) { List<Models.ImageGallery> lsTopic = ImageGalleryBusiness.GetImageTopicPrograms(); foreach (var item in lsTopic) { if (item.ProgramId == id) { ViewData["ls1"] = item; } } if (Session["user_login"] != null) { List<Models.Programs> ls = ProgramsBusiness.GetProgramsById(id); ViewData["program"] = ls[0]; Models.Member ad = Session["user_login"] as Models.Member; Models.Message msg = new Models.Message(); msg.SenderName = ad.FullName; msg.SenderEmail = ad.Email; return View(msg); } else { List<Models.Programs> ls = ProgramsBusiness.GetProgramsById(id); ViewData["program"] = ls[0]; return View(); } }
public void PerformPostMessageOnExistingUserTest() { // act string input = "Bob -> Good game though."; User user = new User { UserId = Guid.NewGuid(), Username = "******" }; Message userMessage = new Message { UserId = user.UserId }; _userManagerMock.Setup(x => x.GetUserByUsername(user.Username, false)).Returns(user); _messageManagerMock.Setup(x => x.AddMessage(user.UserId, input)); var perform = new Post(_userManagerMock.Object, _messageManagerMock.Object); // actual var actual = perform.Perform(input); // assert Assert.AreEqual(actual, string.Empty); _userManagerMock.Verify(x => x.AddUser(It.IsAny<string>()), Times.Never); _messageManagerMock.Verify(x => x.AddMessage(It.IsAny<Guid>(), It.IsAny<string>()), Times.AtLeastOnce); }
public void AddDubplicateUserMessageTest() { // act var user = new User { UserId = Guid.NewGuid(), Username = "******" }; var message = new Message { UserId = user.UserId, Description = "I love the weather today", MessageId = Guid.NewGuid(), PostedDt = DateTime.UtcNow }; _messageRepository.Add(message); _messageRepository.Add(message); // actual var actual = _messageRepository.Get(); // assert Assert.IsNotNull(actual); Assert.AreEqual(actual.MessageId, message.MessageId); }
public Message AddNew(Message message) { this.messages.Add(message); this.messages.SaveChanges(); return message; }
public void Push(Message msg) { lock (lockObject) { this.messages.Enqueue(msg); Monitor.Pulse(lockObject); } }
public static int EditMessage(Message ad) { int upt = 0; try { upt = DataAccessLayer.MessageDA.EditMessage(ad); } catch (Exception) { return 0; } return upt; }
public static int AddMessage(Message ad) { int ins = 0; try { ins = DataAccessLayer.MessageDA.AddMessage(ad); } catch (Exception) { return 0; } return ins; }
public ActionResult AddMsgProcess(FormCollection frm) { int kt = 0; int? programId = null; try { if (frm["ProgramId"] != null && frm["ProgramId"] != "") { programId = int.Parse(frm["programId"]); } // TODO: Add insert logic here Models.Message ad = new Models.Message() { ProgramId = programId, SenderName = frm["SenderName"], SenderEmail = frm["SenderEmail"], Messages = frm["Messages"], Status = 0, IsDeleted = 0 }; kt = MessageBusiness.AddMessage(ad); } catch { kt = 0; } if (kt > 0) { if (frm["sender"] != null) { return RedirectToAction("ProgramDetail", "Programs", new { add = "success", @id = programId }); } else return RedirectToAction("Message", "Message", new { add = "success" }); } else { if (frm["sender"] != null) { return RedirectToAction("ProgramDetail", "Programs", new { add = "error", @id = programId}); } else return RedirectToAction("Message", "Message", new { add = "error" }); } }
// // GET: /Message/ public ActionResult Message() { List<Models.Programs> lsPro = BusinessLogicLayer.ProgramsBusiness.GetAllPrograms(); ViewData["Program"] = new SelectList(lsPro, "Id", "Name"); if (Session["user_login"] != null) { Models.Member ad = Session["user_login"] as Models.Member; Models.Message msg = new Models.Message(); msg.SenderName = ad.FullName; msg.SenderEmail = ad.Email; return View(msg); } else { return View(); } }
public void AddUserMessageChildrenTest() { // act var user = new User { UserId = Guid.NewGuid(), Username = "******" }; var userMessage = new Message { UserId = user.UserId, }; var message1 = new Message { UserId = user.UserId, Description = "Good game though.", MessageId = Guid.NewGuid(), PostedDt = DateTime.UtcNow }; var message2 = new Message { UserId = user.UserId, Description = "Damn! We lost!", MessageId = Guid.NewGuid(), PostedDt = DateTime.UtcNow }; _messageRepository.Add(userMessage); _messageRepository.AddChild(message1); _messageRepository.AddChild(message2); // actual var actual = _messageRepository.GetAll(user).ToList(); // assert Assert.AreEqual(actual.First(x => x.MessageId.Equals(message1.MessageId)).MessageId, message1.MessageId); Assert.AreEqual(actual.First(x => x.MessageId.Equals(message2.MessageId)).MessageId, message2.MessageId); Assert.AreEqual(actual.Count(), 2); }
public async Task<Message> Create(string sender, string receiver, string title, string content, string flag, string notes) { var message = new Message() { SenderId = sender, ReceiverId = receiver, Title = title, Content = content, Flag = flag, Notes = notes, isDeleted = false, isViewed = false, DateCreated = DateTime.UtcNow }; messages.Add(message); await messages.SaveChangesAsync(); return message; }
private static List<Message> AddMessageToList2(DataTable dt) { List<Message> ls = new List<Message>(); try { for (int i = 0; i < dt.Rows.Count; i++) { Message ad = new Message() { ProgramId = int.Parse(dt.Rows[i]["ProgramId"].ToString()), ProgramName = dt.Rows[i]["Name"].ToString(), TotalMessage = int.Parse(dt.Rows[i]["TotalMessage"].ToString()), TotalNewMessage = int.Parse(dt.Rows[i]["TotalNewMessage"].ToString()), TotalReadMessage = int.Parse(dt.Rows[i]["TotalReadMessage"].ToString()), TotalRepliedMessage = int.Parse(dt.Rows[i]["TotalRepliedMessage"].ToString()), }; ls.Add(ad); } } catch (Exception) { return new List<Message>(); } return ls; }
public int Delete(Message dbModel) { this.messages.Delete(dbModel); return this.messages.SaveChanges(); }
public void Handled(Models.Message message) { }
public int Update(Message message) { throw new NotImplementedException(); }
/// <summary> /// Sends a fire and forget command to the device /// </summary> /// <param name="deviceId"></param> /// <param name="command"></param> /// <returns></returns> public async Task SendCommand(string deviceId, dynamic command) { ServiceClient serviceClient = ServiceClient.CreateFromConnectionString(_iotHubConnectionString); byte[] commandAsBytes = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(command)); var notificationMessage = new Message(commandAsBytes); notificationMessage.Ack = DeliveryAcknowledgement.Full; notificationMessage.MessageId = command.MessageId; await AzureRetryHelper.OperationWithBasicRetryAsync(async () => await serviceClient.SendAsync(deviceId, notificationMessage)); await serviceClient.CloseAsync(); }
public void Add(Message message) { this.messages.Add(message); this.messages.SaveChanges(); }
private static List<Message> AddMessageToList(DataTable dt,string flag) { List<Message> ls = new List<Message>(); try { for (int i = 0; i < dt.Rows.Count; i++) { string programName = null; if (flag ==null) { programName= dt.Rows[i]["Name"].ToString(); } int? programId = null; int? replierId = null; if (dt.Rows[i]["ProgramId"].ToString() != null && dt.Rows[i]["ProgramId"].ToString()!="") { programId = int.Parse(dt.Rows[i]["ProgramId"].ToString()); } if (dt.Rows[i]["Replier"].ToString() != null && dt.Rows[i]["Replier"].ToString() != "") { replierId = int.Parse(dt.Rows[i]["Replier"].ToString()); } Message ad = new Message() { Id = int.Parse(dt.Rows[i]["Id"].ToString()), ProgramId = programId, ProgramName =programName, SenderName = dt.Rows[i]["SenderName"].ToString(), SenderEmail = dt.Rows[i]["SenderEmail"].ToString(), Messages = dt.Rows[i]["Message"].ToString(), Status = int.Parse(dt.Rows[i]["Status"].ToString()), ReplierId = replierId, Replier = dt.Rows[i]["UserName"].ToString(), IsDeleted = int.Parse(dt.Rows[i]["IsDeleted"].ToString()) }; ls.Add(ad); } } catch (Exception) { return new List<Message>(); } return ls; }
public void MessageService__Calls_MessageCoordinator_WithProperVolunteerList() { var mockAdminSvc = new Mock<IAdmin>(); var volunteers = new List<Person>(); volunteers.Add(new Person { Id = 1, Email = "email-1", FirstName = "first", LastName = "last" }); volunteers.Add(new Person { Id = 2, Email = "email-2", FirstName = "first", LastName = "last" }); mockAdminSvc.Setup(x => x.GetVolunteersForDate(It.IsAny<int>(), DateTime.Today)).Returns(volunteers); var mockMessageCoordinator = new Mock<IMessageCoordinator>(); var expectedMessage = new Message("body", "subject"); var expectedRecipients = new List<MessageRecipient>(); expectedRecipients.Add(new MessageRecipient { EmailAddress = "email-1", Name = "first last" }); expectedRecipients.Add(new MessageRecipient { EmailAddress = "email-2", Name = "first last" }); var sut = new MessageService(mockAdminSvc.Object, mockMessageCoordinator.Object); sut.SendMessageToDisasterVolunteers(new RecipientCriterion(42), expectedMessage); mockMessageCoordinator.Verify(x => x.SendMessage(expectedMessage, It.Is<List<MessageRecipient>>(y => y.Count.Equals(2))), Times.Once()); }
public void MessageService__DoesNotFail_With_Empty_VolunteerList() { const string sender = "Sender Name"; var mockAdminSvc = new Mock<IAdmin>(); var volunteers = new List<Person>(); volunteers.Add(new Person { Id = 1, Email = "email-1", FirstName = "first", LastName = "last" }); volunteers.Add(new Person { Id = 2, Email = "email-2", FirstName = "first", LastName = "last" }); mockAdminSvc.Setup(x => x.GetVolunteersForDate(It.IsAny<int>(), DateTime.Today, false, false)).Returns(volunteers); var mockMessageCoordinator = new Mock<IMessageCoordinator>(); var expectedMessage = new Message("body", "subject"); var expectedRecipients = new List<MessageRecipient>(); var sut = new MessageService(mockAdminSvc.Object, mockMessageCoordinator.Object); sut.SendMessageToDisasterVolunteers(expectedMessage, new RecipientCriterion(42), sender); mockMessageCoordinator.Verify(x => x.SendMessage(expectedMessage, It.Is<List<MessageRecipient>>(y => y.Count.Equals(2)), sender), Times.Once()); }