private static MessageToCompanyModel MapToMessageToCompanyModel(MessageFromBuilding messageFromBulidingDB, AccessControlSystemEntities context) { MessageToCompanyModel messageToCompany = new MessageToCompanyModel(); messageToCompany.Id = messageFromBulidingDB.Id; messageToCompany.Text = messageFromBulidingDB.Value; messageToCompany.Date = messageFromBulidingDB.Date; messageToCompany.Subject = messageFromBulidingDB.Subject; return(messageToCompany); }
public MessageToCompanyModel GetMessageFromBuilding(int messageId) { AccessControlSystemEntities context = new AccessControlSystemEntities(); try { MessageFromBuilding message = context.MessageFromBuildings.Where(x => x.Id == messageId).FirstOrDefault(); return(MapToMessageToCompanyModel(message, context)); } catch (Exception e) { } return(null); }
public void AddNewMessages(MessagesFromBulidingModel messageModel) { AccessControlSystemEntities context = new AccessControlSystemEntities(); MessageFromBuilding messageDB = new MessageFromBuilding(); messageDB.Subject = messageModel.Subject; messageDB.Value = messageModel.Text; context.MessageFromBuildings.Add(messageDB); context.SaveChanges(); foreach (var item in messageModel.Companies) { MessagesOfCompany newDBItem = new MessagesOfCompany(); newDBItem.CompanyId = item.Id; newDBItem.MessageFromBuildingId = messageDB.Id; context.MessagesOfCompanies.Add(newDBItem); } context.SaveChanges(); }