Exemple #1
0
        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);
        }
Exemple #2
0
        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();
        }