/// <summary> /// Create Message Async /// </summary> /// <param name="messageExtended"></param> /// <returns></returns> public async Task <Message> CreateMessageAsync(MessageExtended messageExtended) { var result = await ExecuteAsync <Message>(async (message) => { var mes = _messageDbContext.Messages.Add(new Message { Name = messageExtended.Name, State = messageExtended.State, Template = messageExtended.Template, Type = messageExtended.Type }); var users = messageExtended.UserIds.Select( u => new MessageUser() { MessageId = mes.Entity.Id, UserId = u } ).ToArray(); _messageDbContext.MessageUser.AddRange(users); await _messageDbContext.SaveChangesAsync(CancellationToken.None); }, "GetMessageById", messageExtended); return(result); }
public static object MappingMsgInforByName(MessageExtended msg, string header) { if (header.IsMemberOfList(DeliveryHeader.Ordernr, DeliveryHeader.Ordernumbmer)) { return(msg.OrderNo); } if (header.IsMemberOfList(DeliveryHeader.Rad, DeliveryHeader.AntalOrderrader)) { return(msg.OrderLine); } if (header.Equals(DeliveryHeader.Artikel)) { return(msg.ItemName); } if (header.IsMemberOfList(DeliveryHeader.BestKvantitet, DeliveryHeader.PlaneradKvantitet, DeliveryHeader.BestKvant, DeliveryHeader.SummaKvantitet, DeliveryHeader.Summa)) { return(msg.OrderQuantity); } if (header.Equals(DeliveryHeader.Silo)) { return(msg.Container); } if (header.IsMemberOfList(DeliveryHeader.Planeradankomst, DeliveryHeader.PlaneradHamtning, DeliveryHeader.PlanAnkomst)) { return(msg.PlannedDeliveryDate != null ? $"{msg.PlannedDeliveryDate:yyyy-MM-dd}" : string.Empty); } if (header.IsMemberOfList(DeliveryHeader.FranFabrik, DeliveryHeader.FranLager, DeliveryHeader.LevererasTill, DeliveryHeader.FranFabrikLager, DeliveryHeader.TillLager)) { return(msg.Warehouse); } if (header.IsMemberOfList(DeliveryHeader.Levererat, DeliveryHeader.Hamtat)) { return(msg.DeliveryDate != null ? $"{msg.DeliveryDate:yyyy-MM-dd}" : string.Empty); } if (header.IsMemberOfList(DeliveryHeader.LevKvant, DeliveryHeader.LevKvantitet)) { return(msg.DeliveredQuantity); } if (header.Equals(DeliveryHeader.Enhet)) { return(msg.Unit); } if (header.IsMemberOfList(DeliveryHeader.Sandning, DeliveryHeader.Sandnr)) { return(msg.FreightNo); } if (header.Equals(DeliveryHeader.Transportor)) { return(msg.Carrier); } if (header.Equals(DeliveryHeader.Bil)) { return(msg.CarNo); } if (header.Equals(DeliveryHeader.TelTransportor)) { return(msg.CarMobileNo); } return(header.IsMemberOfList(DeliveryHeader.TelefonBil) ? msg.CarMobileNo : null); }
private static List <object> GetDeliveryItems(MessageExtended msg, List <string> headerItems) { if (headerItems.IsNullOrEmpty() || msg == null) { return(new List <object>()); } return(headerItems.Select(header => DeliveryMessageHelper.MappingMsgInforByName(msg, header)).ToList()); }
public MessagesViewModel(int user_id) { UserModel um = new UserModel(user_id); CallerUserId = user_id; Unread_Number = um.Unread_Messages_Quantity(0, 1) + um.Unread_Messages_Quantity(0, 2) + um.Unread_Messages_Quantity(0, 3); List <message> _message = um.UserMessages(0, 1).ToList(); List <message> _message1 = um.UserMessages(0, 2).ToList(); List <message> _message2 = um.UserMessages(0, 3).ToList(); _message.AddRange(_message1); _message.AddRange(_message2); _message = _message.OrderByDescending(item => item.created_dt).ToList(); foreach (message temp_message in _message) { _extended = new MessageExtended(temp_message.id, CallerUserId); _messages.Add(_extended); } _messages = _messages.OrderByDescending(item => item._message.created_dt).ToList(); }
public CaseMessagesViewModel BindMessageToViewMessage(message _message, int caller_id) { IDateTimeHelper m_DateTimeHelper = new DateTimeHelper(); GlobalFunctions glb = new GlobalFunctions(); UserModel um = new UserModel(caller_id); CaseMessagesViewModel vm_message = new CaseMessagesViewModel(); ReportModel rm = new ReportModel(_message.report_id); string _month_name = ""; string _sender_name = ""; #region message_sender_name user temp_sender = um.GetById(_message.sender_id); if ((temp_sender != null) && (temp_sender.id != 0)) { _sender_name = ""; if (_message.sender_id == caller_id) { _sender_name = GlobalRes.You; } else { if (temp_sender.role_id == 8) { if ((rm._report.incident_anonymity_id == 1) || (rm._report.incident_anonymity_id == 2)) { _sender_name = GlobalRes.anonymous_reporter; } else { _sender_name = GlobalRes.Reporter; } } else { if (_message.sender_id != caller_id) { _sender_name = (temp_sender.first_nm + " " + temp_sender.last_nm).Trim(); } } } } #endregion vm_message.sender_name = _sender_name; vm_message.sender_id = _message.sender_id; #region sender photo if (temp_sender.photo_path.Trim() != "") { vm_message.sender_photo = temp_sender.photo_path.Trim(); } else { vm_message.sender_photo = "~/Content/Icons/anonimousReporterIcon.png"; } #endregion #region Created Date vm_message.created_dt = ""; if (_message.created_dt.HasValue) { _month_name = m_DateTimeHelper.GetFullMonth(_message.created_dt.Value.Month); vm_message.created_dt = _month_name + " " + _message.created_dt.Value.Day.ToString(); } #endregion vm_message.Id = _message.id; vm_message.body_tx = _message.body_tx; vm_message.reporter_access = _message.reporter_access; vm_message.report_id = report_id; var _extended = new MessageExtended(vm_message.Id, caller_id); vm_message.isReaded = _extended.IsRead(); return(vm_message); }
public async Task <ActionResult <Message> > CreateMessageAsync([FromBody] MessageExtended messageExtended) { return(await _messageController.CreateMessageAsync(messageExtended)); }
private static bool DeliveryHasDelayedToReceived(MessageExtended delivery) => delivery.DeliveryDatePassed;