public async Task InsertMessageUserAsync(string userId, string content) { var strategy = base.BaseData.BaseDB.BaseDataContext.Database.CreateExecutionStrategy(); await strategy.ExecuteAsync(async() => { await BeginTransactionAsync(async() => { MessagesDto messagesDto = new MessagesDto() { Title = content, Content = content, Method = 1, Status = 2 }; var messageInfo = await messagesService.CreateOrUpdateAsync(messagesDto); MessageDetailDto messageDetailDto = new MessageDetailDto() { MessageId = messageInfo.Id, UserId = userId, IsRead = 2 }; await CreateOrUpdateAsync(messageDetailDto); }); }); }
/// <summary> /// Handler=Save /// </summary> /// <returns></returns> public async Task <IActionResult> OnPostSaveAsync([FromBody] MessagesExtendDto messagesExtendDto) { SenparcTrace.Log($"messagesExtendDto----{messagesExtendDto.ToJson()}"); if (messagesExtendDto == null) { return(Ok(false)); } MessagesDto messagesDto = new MessagesDto { Id = messagesExtendDto.Id, Title = messagesExtendDto.Title, Content = messagesExtendDto.Content, Method = messagesExtendDto.Method, Type = messagesExtendDto.Type, Status = messagesExtendDto.Status }; var strategy = _messagesService.BaseData.BaseDB.BaseDataContext.Database.CreateExecutionStrategy(); await strategy.ExecuteAsync(async() => { await _messagesService.BeginTransactionAsync(async() => { var messages = await _messagesService.CreateOrUpdateAsync(messagesDto); await messageDetailService.InsertMessageUserAsync(messages.Id, messagesExtendDto.RelationUser); }); }); return(Ok(true)); }
public static AllMessagesVM FromDto(MessagesDto data) { return(new AllMessagesVM { userIdSend = data.userIdSend, userId = data.userId, conversationId = data.conversationId, message = data.message }); }
public void Update(MessagesDto messagesDto) { LastUpdateTime = messagesDto.LastUpdateTime; Title = messagesDto.Title; Content = messagesDto.Content; Method = messagesDto.Method; SendTime = messagesDto.SendTime; Type = messagesDto.Type; Status = messagesDto.Status; }
public async Task <IActionResult> ContactUs(MessageCreateInputModel input) { var dto = new MessagesDto { FirstName = input.FirstName, LastName = input.LastName, Email = input.Email, Subject = input.Subject, }; await this.messagesService.CreateMessageAsync(dto); return(this.Redirect("/")); }
public async Task<Messages> CreateOrUpdateAsync(MessagesDto dto) { Messages messages; if (String.IsNullOrEmpty(dto.Id)) { messages = new Messages(dto); } else { messages = await GetObjectAsync(_ => _.Id == dto.Id); messages.Update(dto); } await SaveObjectAsync(messages); return messages; }
private MessagesDto SaveMessage(int alarmId, string userName, string message) { var messageDto = new MessagesDto { UserName = userName, AlarmId = alarmId, Message = message, MessageTime = DateTime.Now.AddHours(1) }; var _context = new ApplicationDbContext(); var messageObj = Mapper.Map <MessagesDto, Messages>(messageDto); _context.Messages.Add(messageObj); _context.SaveChanges(); messageDto.Id = messageObj.Id; return(messageDto); }
public async Task CreateMessageAsync(MessagesDto dto) { if (this.messagesRepository.All().Where(x => x.Email == dto.Email).Count() <= 1) { var msg = new ContactMessage { FirstName = dto.FirstName, LastName = dto.LastName, Email = dto.Email, Subject = dto.Subject, }; await this.messagesRepository.AddAsync(msg); await this.messagesRepository.SaveChangesAsync(); } else { throw new Exception("You cannot have more than 2 unanswered messages."); } }
public async Task<HttpResponseMessage> SaveMessageAttachment() { string userId = User.Identity.GetUserId(); string toUserId = string.Empty; bool isBulk = false; MediaStatusMessage stat = new MediaStatusMessage(); // Check if the request contains multipart/form-data. if (!Request.Content.IsMimeMultipartContent()) { throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType); } MessagesDto msg = new MessagesDto(); MessageMediaDto msgMedia = new MessageMediaDto(); string defaultPath = AppSettings.Get<string>(ConfigConstants.DefaultMessageMediaSavePath); string defaultUrlPath = AppSettings.Get<string>(ConfigConstants.DefaultMessageMediaUrlPath); string root = System.Web.HttpContext.Current.Server.MapPath("~/" + defaultPath); var provider = new MultipartFormDataStreamProvider(root); string mediaUrl = string.Empty; try { await Request.Content.ReadAsMultipartAsync(provider); foreach (var key in provider.FormData.AllKeys) { foreach (var val in provider.FormData.GetValues(key)) { if (key == "ToUserId") { toUserId = val; } else if (key == "IsBulkMessage") { isBulk = val == "1" ? true : false; } } } foreach (MultipartFileData file in provider.FileData) { string originalFileName = file.Headers.ContentDisposition.FileName.Replace("\"", string.Empty); string fileExtension = Path.GetExtension(originalFileName); string fname = Guid.NewGuid().ToString(); string fileName = fname + fileExtension; string outputPath = Path.Combine(root, fileName); System.IO.File.Move(file.LocalFileName, outputPath); FileInfo fileInfo = new FileInfo(outputPath); string size = Convert.ToDouble(fileInfo.Length / 1024) + string.Empty; mediaUrl = AppSettings.Get<string>("ApiBaseUrl") + defaultUrlPath + "/" + fileName; if (isBulk) { if (User.IsInRole(RoleName.CompanyRole)) { this.youfferMessageService.SendBulkMessage(userId, string.Empty, originalFileName, fileExtension, size, fname); } } else { if (User.IsInRole(RoleName.CompanyRole)) { msg.UserId = toUserId; msg.CompanyId = userId; } else if (User.IsInRole(RoleName.CustomerRole)) { msg.CompanyId = toUserId; msg.UserId = userId; } msg.FromUser = msg.CreatedBy = msg.ModifiedBy = userId; msg.ToUser = toUserId; msg.DoesContainMedia = true; msg.Message = string.Empty; msg.IsDeleted = false; msg = this.youfferMessageService.CreateMessage(msg); this.LoggerService.LogException("Message - json -" + JsonConvert.SerializeObject(msg)); msgMedia.MessageId = msg.Id; msgMedia.Size = size; msgMedia.Extension = fileExtension; msgMedia.FileName = fileName; msgMedia.OriginalFileName = file.Headers.ContentDisposition.FileName.Replace("\"", string.Empty); msgMedia.IsDeleted = false; msgMedia.IsSuccess = true; msgMedia.CreatedBy = userId; msgMedia.ModifiedBy = userId; this.youfferMessageService.MakeMessageMediaEntry(msgMedia); this.LoggerService.LogException("Message Media - json -" + JsonConvert.SerializeObject(msgMedia)); int unreadMsgCount = this.youfferMessageService.GetUnreadMsgCount(msg.UserId, false); if (User.IsInRole(RoleName.CustomerRole)) { OrganisationModel toUser = this.crmManagerService.GetOrganisation(toUserId); ContactModel fromUser = this.crmManagerService.GetContact(userId); if (!string.IsNullOrEmpty(toUser.GCMId)) { this.pushMessageService.SendMessageNotificationToAndroid(toUser.GCMId, msg.Id.ToString(), msg.Message, fromUser.FirstName, Notification.companymsg.ToString()); } if (!string.IsNullOrEmpty(toUser.UDId)) { this.pushMessageService.SendMessageNotificationToiOS(toUser.UDId, msg.Id.ToString(), msg.Message, fromUser.FirstName, unreadMsgCount, Notification.companymsg.ToString()); } } else if (User.IsInRole(RoleName.CompanyRole)) { ContactModel toUser = this.crmManagerService.GetContact(toUserId); OrganisationModel fromUser = this.crmManagerService.GetOrganisation(userId); if (!string.IsNullOrEmpty(toUser.GCMId)) { this.pushMessageService.SendMessageNotificationToAndroid(toUser.GCMId, msg.Id.ToString(), msg.Message, fromUser.AccountName, Notification.usermsg.ToString()); } if (!string.IsNullOrEmpty(toUser.UDId)) { this.pushMessageService.SendMessageNotificationToiOS(toUser.UDId, msg.Id.ToString(), msg.Message, fromUser.AccountName, unreadMsgCount, Notification.usermsg.ToString()); } } } } stat.IsSuccess = true; stat.MediaUrl = mediaUrl; return Request.CreateResponse(HttpStatusCode.OK, stat); } catch (Exception ex) { this.LoggerService.LogException("SaveMessageAttachment : " + ex.Message); stat.IsSuccess = false; stat.MediaUrl = string.Empty; return Request.CreateResponse(HttpStatusCode.BadRequest, stat); } }