/// <summary> /// 增加一条记录,返回新的ID号。需要有一个单一主键,并且开启有标识符属性(异步方式) /// </summary> /// <param name="entity">实体模型</param> /// <returns></returns> public virtual async Task <int> InsertAsync(UserMessageEntity entity) { Dictionary <string, object> dict = new Dictionary <string, object>(); GetParameters(entity, dict); string strSQL = "insert into UserMessage (" + "Title," + "Content," + "Sender," + "Incept," + "SendTime," + "IsSend," + "IsDelInbox," + "IsDelSendbox," + "IsRead) " + "values(" + "@Title," + "@Content," + "@Sender," + "@Incept," + "@SendTime," + "@IsSend," + "@IsDelInbox," + "@IsDelSendbox," + "@IsRead)"; return(await Task.Run(() => _DB.ReturnID(strSQL, dict))); }
/// <summary> /// 增加一条记录 /// </summary> /// <param name="entity">实体模型</param> /// <returns></returns> public virtual bool Add(UserMessageEntity entity) { Dictionary <string, object> dict = new Dictionary <string, object>(); GetParameters(entity, dict); string strSQL = "insert into UserMessage (" + "Title," + "Content," + "Sender," + "Incept," + "SendTime," + "IsSend," + "IsDelInbox," + "IsDelSendbox," + "IsRead) " + "values(" + "@Title," + "@Content," + "@Sender," + "@Incept," + "@SendTime," + "@IsSend," + "@IsDelInbox," + "@IsDelSendbox," + "@IsRead)"; return(_DB.ExeSQLResult(strSQL, dict)); }
protected UserMessageAdminDisplayModel UserMessageEntityToAdminDisplayModel(UserMessageEntity entity) { ApartmentEntity apartment; try { apartment = _dbContext.Apartments.First(a => a.Id == entity.ApartmentId); } catch (System.InvalidOperationException error) { apartment = null; } if (apartment != null) { return(new UserMessageAdminDisplayModel { Id = entity.Id, Name = entity.Name, Email = entity.Email, Message = entity.Message, ApartmentTitle = apartment.Name, ApartmentId = entity.ApartmentId }); } else { return(new UserMessageAdminDisplayModel { Id = entity.Id, Name = entity.Name, Email = entity.Email, Message = entity.Message }); } }
/// <summary> /// 把实体类转换成键/值对集合 /// </summary> /// <param name="entity"></param> /// <param name="dict"></param> private static void GetParameters(UserMessageEntity entity, Dictionary <string, object> dict) { dict.Add("MessageID", entity.MessageID); dict.Add("Title", entity.Title); dict.Add("Content", entity.Content); dict.Add("Sender", entity.Sender); dict.Add("Incept", entity.Incept); dict.Add("SendTime", entity.SendTime); dict.Add("IsSend", entity.IsSend); dict.Add("IsDelInbox", entity.IsDelInbox); dict.Add("IsDelSendbox", entity.IsDelSendbox); dict.Add("IsRead", entity.IsRead); }
/// <summary> /// 获取实体(异步方式) /// </summary> /// <param name="strWhere">参数化查询条件(例如: and Name = @Name )</param> /// <param name="dict">参数的名/值集合</param> /// <returns></returns> public virtual async Task <UserMessageEntity> GetEntityAsync(string strWhere, Dictionary <string, object> dict = null) { UserMessageEntity obj = null; string strSQL = "select top 1 * from UserMessage where 1=1 " + strWhere; using (NullableDataReader reader = await Task.Run(() => _DB.GetDataReader(strSQL, dict))) { if (reader.Read()) { obj = GetEntityFromrdr(reader); } } return(obj); }
/// <summary> /// 通过数据读取器生成实体类 /// </summary> /// <param name="rdr"></param> /// <returns></returns> private static UserMessageEntity GetEntityFromrdr(NullableDataReader rdr) { UserMessageEntity info = new UserMessageEntity(); info.MessageID = rdr.GetInt32("MessageID"); info.Title = rdr.GetString("Title"); info.Content = rdr.GetString("Content"); info.Sender = rdr.GetString("Sender"); info.Incept = rdr.GetString("Incept"); info.SendTime = rdr.GetNullableDateTime("SendTime"); info.IsSend = rdr.GetInt32("IsSend"); info.IsDelInbox = rdr.GetInt32("IsDelInbox"); info.IsDelSendbox = rdr.GetInt32("IsDelSendbox"); info.IsRead = rdr.GetInt32("IsRead"); return(info); }
public static async Task <string> SaveMessageAndGetExtId(string message) { string extId = null; // We cannot use a transaction in heterogeneous storage mediums. An orphaned message on Azure Table is not a problem. The main message metadata is in the database anyway. if (!String.IsNullOrWhiteSpace(message)) { extId = KeyUtils.GetTwelveBase32Digits(); var entity = new UserMessageEntity { PartitionKey = extId, RowKey = String.Empty, Text = message, }; await AzureStorageUtils.InsertEntityAsync(AzureStorageUtils.TableNames.UserMessages, entity); } return(extId); }
public ApartmentContactResponseModel Post(UserMessageModel userMessage) { var entity = new UserMessageEntity { Name = userMessage.Name, Email = userMessage.Email, Message = userMessage.Message, ApartmentId = userMessage.ApartmentId, DateSent = DateTime.Now }; _dbContext.UserMessages.Add(entity); _dbContext.SaveChanges(); return(new ApartmentContactResponseModel { Message = "We received your message and will respond within the next 24 hours!" }); }
/// <summary> /// 更新一条记录(异步方式) /// </summary> /// <param name="entity">实体模型</param> /// <returns></returns> public virtual async Task <bool> UpdateAsync(UserMessageEntity entity) { Dictionary <string, object> dict = new Dictionary <string, object>(); GetParameters(entity, dict); string strSQL = "Update UserMessage SET " + "Title = @Title," + "Content = @Content," + "Sender = @Sender," + "Incept = @Incept," + "SendTime = @SendTime," + "IsSend = @IsSend," + "IsDelInbox = @IsDelInbox," + "IsDelSendbox = @IsDelSendbox," + "IsRead = @IsRead" + " WHERE " + "MessageID = @MessageID"; return(await Task.Run(() => _DB.ExeSQLResult(strSQL, dict))); }
public async Task <ActionResult> MessageSend(MessageViewModel viewModel, IFormCollection collection) { #region 添加并发送 StringBuilder sbIncept = new StringBuilder(); switch (viewModel.InceptType) { case 0: //所有会员 var listAll = await _UsersServiceApp.QueryDynamicAsync <UsersEntity>(p => p.UserID > 0, p => p.UserName); listAll.ForEach(item => { StringHelper.AppendString(sbIncept, item); }); break; case 1: //指定会员 string Incept = collection["ctlSelectUser"]; if (string.IsNullOrEmpty(Incept)) { ModelState.AddModelError(string.Empty, "收件人不能为空"); return(View(viewModel)); } string[] strArray = Incept.Split(new char[] { ',' }); for (int j = 0; j < strArray.Length; j++) { if (_UsersServiceApp.IsExist(p => p.UserName == strArray[j])) { StringHelper.AppendString(sbIncept, strArray[j]); } } break; case 2: //指定会员组 var InceptGroup = collection["InceptGroup"]; if (string.IsNullOrEmpty(InceptGroup)) { ModelState.AddModelError(string.Empty, "收件人会员组不能为空"); return(View(viewModel)); } var listGroup = await _UsersServiceApp.SqlQueryOneAsync <string>("select UserName from Users where GroupID in (" + InceptGroup + ")"); List <string> list = (List <string>)listGroup; list.ForEach(item => { StringHelper.AppendString(sbIncept, item); }); break; } if (string.IsNullOrEmpty(sbIncept.ToString())) { ModelState.AddModelError(string.Empty, "收件人不存在"); return(View(viewModel)); } foreach (string strItem in sbIncept.ToString().Split(new char[] { ',' })) { var entity = new UserMessageEntity(); entity.Title = viewModel.Title; entity.Content = viewModel.Content; entity.Sender = viewModel.Sender; entity.Incept = strItem; entity.SendTime = DateTime.Now; entity.IsSend = 1; entity.IsRead = 0; entity.IsDelInbox = 0; entity.IsDelSendbox = 0; await _UserMessageServiceApp.AddAsync(entity); } #endregion viewModel.result = "ok"; return(View(viewModel)); }
/// <summary> /// 增加或更新一条记录(异步方式) /// </summary> /// <param name="entity">实体模型</param> /// <param name="IsSave">是否增加</param> /// <returns></returns> public virtual async Task <bool> AddOrUpdateAsync(UserMessageEntity entity, bool IsSave) { return(IsSave ? await AddAsync(entity) : await UpdateAsync(entity)); }
/// <summary> /// 增加或更新一条记录 /// </summary> /// <param name="entity">实体模型</param> /// <param name="IsSave">是否增加</param> /// <returns></returns> public virtual bool AddOrUpdate(UserMessageEntity entity, bool IsSave) { return(IsSave ? Add(entity) : Update(entity)); }