public static void SendMessage(communicationModel commModel, DateTime validFrom, DateTime validTo, int UserID) { using (DSRCManagementSystemEntities1 dbHrms = new DSRCManagementSystemEntities1()) { communicationMessage commMessage = new communicationMessage(); commMessage.MessageText = commModel.Message.Replace(System.Environment.NewLine, "<br />"); commMessage.UserID = UserID; commMessage.ShowComments = commModel.showComments; commMessage.ShowToAll = commModel.showToAll; commMessage.Valid_From = validFrom /*commModel.dateFrom*/; commMessage.Valid_To = validTo /*commModel.dateTo*/; commMessage.MessageType = commModel.messageTypeId; dbHrms.AddTocommunicationMessages(commMessage); dbHrms.SaveChanges(); //commModel.selectedMembers.ForEach(x => commModel.UserList.ForEach(x => { UserMessage userMessage = new UserMessage(); userMessage.EmployeeId = Convert.ToInt32(x); userMessage.MessageId = commMessage.MessageId; dbHrms.AddToUserMessages(userMessage); dbHrms.SaveChanges(); }); } }