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; }
/// <summary> /// Updates demand quote with comments. /// </summary> /// <param name="quote"></param> /// <returns></returns> public DemandQuote UpdateQuoteRecord(DemandQuote quote) { ParameterChecker.Check(quote, "Quote"); ParameterChecker.Check(quote.ContactName, "Contact Name"); //ParameterChecker.Check(quote.ContactPhoneNumber, "Contact Phone Numer"); var conn = DBHelper.GetSqlConnection(); try { var currentTime = DateTime.Now; using (TransactionScope scope = new TransactionScope()) { conn.Open(); quote.LastUpdatedTimestamp = currentTime; quote = quoteDao.InsertOrUpdateDemandQuote(conn, quote); if (quote.QuoteHistories.HasItem()) { foreach (var item in quote.QuoteHistories) { if (item.Operation == Operation.Add) { item.QuoteId = quote.QuoteId; item.InsertedTimestamp = currentTime; item.HasRead = false; item.IsActive = true; quoteDao.InsertDemandQuoteHistory(conn, item); } } } scope.Complete(); } } catch (Exception ex) { LogService.Log("Updates demand quote with comments.", ex.ToString()); } finally { conn.Close(); } return quote; }
/// <summary> /// Inserts or update demand quote entity and return. /// </summary> /// <param name="conn"></param> /// <param name="quote"></param> /// <returns></returns> public DemandQuote InsertOrUpdateDemandQuote(SqlConnection conn, DemandQuote quote) { var quoteId = quote.QuoteId; SqlParameter[] parameters = new SqlParameter[] { new SqlParameter(Parameter_QuoteId, quote.QuoteId), new SqlParameter(Parameter_WeChatUserId, quote.WeChatUserId), new SqlParameter(Parameter_DemandId, quote.DemandId), new SqlParameter(Parameter_ContactName, quote.ContactName), new SqlParameter(Parameter_ContactPhoneNumber, quote.ContactPhoneNumber), new SqlParameter(Parameter_QuotePrice, quote.QuotePrice), new SqlParameter(Parameter_HandleStatus, quote.HandleStatus), new SqlParameter(Parameter_AcceptStatus, quote.AcceptStatus), new SqlParameter(Parameter_InsertedTimestamp, quote.InsertedTimestamp), new SqlParameter(Parameter_LastUpdatedTimestamp, quote.LastUpdatedTimestamp), new SqlParameter(Parameter_IsActive, quote.IsActive) }; using (var reader = DBHelper.RunProcedure(conn, SP_InsertOrUpdateDemandQuote, parameters)) { while(reader.Read()) { quoteId = reader[0].DBToInt32(); } } quote.QuoteId = quoteId; return quote; }
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); }