/// <summary> /// Inserts demand quote history. /// </summary> /// <param name="conn"></param> /// <param name="history"></param> /// <returns></returns> public bool InsertDemandQuoteHistory(SqlConnection conn, DemandQuoteHistory history) { SqlParameter[] parameters = new SqlParameter[] { new SqlParameter(Parameter_QuoteId, history.QuoteId), new SqlParameter(Parameter_WeChatUserId, history.WeChatUserId), new SqlParameter(Parameter_Comments, history.Comments), new SqlParameter(Parameter_HasRead, history.HasRead), new SqlParameter(Parameter_InsertedTimestamp, history.InsertedTimestamp), new SqlParameter(Parameter_IsActive, history.IsActive), }; return DBHelper.RunNonQueryProcedure(conn, SP_InsertDemandQuoteHistory, parameters) > 0; }
static DemandQuote NewDemandQuotesEntity() { var quotes = new DemandQuote() { AcceptStatus = DemandQuoteStatus.Wait.ToString(), ContactName = "Richard", ContactPhoneNumber = "13888888888", DemandId = 1, HandleStatus = false, InsertedTimestamp = DateTime.Now, IsActive = true, LastUpdatedTimestamp = DateTime.Now, QuotePrice = 1000, WeChatUserId = 1 }; var quoteHistory = new DemandQuoteHistory() { Comments = "Quote comments", HasRead = false, InsertedTimestamp = DateTime.Now, IsActive = true, WeChatUserId = 1 }; quotes.QuoteHistories.Add(quoteHistory); return quotes; }
public ActionResult AddQuoteHistory(int quoteId, string comments) { string errorMessage = string.Empty; if (string.IsNullOrWhiteSpace(comments)) { errorMessage = "请输入留言内容!"; } else { DemandQuote quote = quoteService.GetDemandQuote(quoteId, false); if (!quote.IsNotNull()) { errorMessage = "报价记录不存在或已被删除!"; } else { var history = new DemandQuoteHistory() { Comments = comments, Operation = Operation.Add, QuoteId = quoteId, WeChatUserId = CurrentWeChatUser.Id }; var result = quoteService.NewQuoteHistory(history); if (!result) { errorMessage = "留言消息发送失败!"; } else { if (quote.WeChatUserId == CurrentWeChatUser.Id) { // Sends notification to wechat client. Task.Factory.StartNew(() => { var demand = demandService.GetDemandById(quote.DemandId); if (demand.IsNotNull()) { var toWeChatUser = userService.GetWeChatUser(demand.UserId); if (toWeChatUser.IsNotNull()) { SendNotification(comments, quote.QuoteId, toWeChatUser.OpenId); } } }); } else { Task.Factory.StartNew(() => { var toWeChatUser = userService.GetWeChatUserByWeChatUserId(quote.WeChatUserId); if (toWeChatUser.IsNotNull()) { SendNotification(comments, quote.QuoteId, toWeChatUser.OpenId); } }); } } } } return Content(errorMessage); }
/// <summary> /// Adds new demand comments. /// </summary> /// <param name="quoteHistory"></param> /// <returns></returns> public bool NewQuoteHistory(DemandQuoteHistory quoteHistory) { ParameterChecker.Check(quoteHistory, "Quote History"); ParameterChecker.Check(quoteHistory.Comments, "Quote History comments"); var isSuccessful = false; var conn = DBHelper.GetSqlConnection(); try { var currentTime = DateTime.Now; using (TransactionScope scope = new TransactionScope()) { conn.Open(); var parentQuote = quoteDao.SelectDemandQuoteByQuoteId(conn, quoteHistory.QuoteId, false); if (parentQuote.IsNotNull()) { // Updates parent quote. parentQuote.LastUpdatedTimestamp = currentTime; quoteDao.InsertOrUpdateDemandQuote(conn, parentQuote); quoteHistory.InsertedTimestamp = currentTime; quoteHistory.HasRead = false; quoteHistory.IsActive = true; // Inserts quote history entity. isSuccessful = quoteDao.InsertDemandQuoteHistory(conn, quoteHistory); } scope.Complete(); } } catch (Exception ex) { LogService.Log("Failed to add new demand comments.", ex.ToString()); } finally { conn.Close(); } return isSuccessful; }
public ActionResult Quote(int demandId, string contactName, string contactTitle, //string contactPhone, decimal quotePrice, string quoteDetail) { string errorMessage = string.Empty; int quoteId = 0; try { // Check parameters. if (string.IsNullOrWhiteSpace(contactName) || //string.IsNullOrWhiteSpace(contactPhone) || string.IsNullOrWhiteSpace(quoteDetail)) { errorMessage = "请输入您的联系方式及报价细则!"; } else if (quotePrice < 0) { errorMessage = "请输入正确的报价金额或报名人数!"; } else { var demand = demandService.GetDemandById(demandId); if (demand.IsNotNull()) { contactTitle = contactTitle.Equals("2", StringComparison.InvariantCultureIgnoreCase) ? "女士" : "先生"; DemandQuote quote = new DemandQuote() { ContactName = contactName + contactTitle, ContactPhoneNumber = string.Empty,//contactPhone, DemandId = demandId, WeChatUserId = CurrentWeChatUser.Id, QuotePrice = quotePrice }; DemandQuoteHistory quoteHistory = new DemandQuoteHistory() { Comments = quoteDetail, Operation = Operation.Add, WeChatUserId = quote.WeChatUserId }; quote.QuoteHistories.Add(quoteHistory); // Savas to database. quote = quoteService.NewQuoteRecord(quote); quoteId = quote.QuoteId; // Sends notification to wechat client. //var message = quote.ContactName + "报价/报名" + (int)quote.QuotePrice + "元/人"; var message = string.Empty; Task.Factory.StartNew(() => { var toWeChatUser = userService.GetWeChatUser(demand.UserId); if (toWeChatUser.IsNotNull()) { SendNotification(message, quote.QuoteId, toWeChatUser.OpenId); } }); } else { errorMessage = "需求不存在或已删除!"; } } } catch (Exception ex) { LogService.LogWexin("需求报价失败", ex.ToString()); errorMessage = "报价失败"; } if (!string.IsNullOrEmpty(errorMessage)) { ViewData["ErrorMessage"] = errorMessage; return View(); } return Redirect("/wechat/quote/detail?quoteId=" + quoteId); }