private static Bill GenerateWebmoneyBill(FormCollection collection) { WebmoneyBill bill = new WebmoneyBill(); bill.WM_Purse = collection["wm_purse"]; return(bill); }
public HttpResponseMessage Post([FromBody] Bill bill) { DateTime changeTime = DateTime.Now; WebmoneyBill wmBill = bill as WebmoneyBill; BankBill pbBill = bill as BankBill; using (SqlConnection connection = new SqlConnection(System.Web.Configuration.WebConfigurationManager.ConnectionStrings["DBCS"].ConnectionString)) { StringBuilder cmdBuilder = new StringBuilder(""); cmdBuilder.Append("INSERT INTO Bills VALUES(@AppId, @AdvancePercent, @Price, @StatusChangeTime, @Currency, @Type, @AdvanceDeadline, @MainDeadline, @DetailsId);"); cmdBuilder.Append("UPDATE Applications SET STATUS='ADVANCE_PENDING' WHERE ID=@AppId;"); Dictionary <string, object> values = new Dictionary <string, object>(); bill.StatusChangeTime = changeTime; values.Add("@AppId", bill.ApplicationId); values.Add("@AdvancePercent", bill.AdvancePercent); values.Add("@Price", bill.Price); values.Add("@StatusChangeTime", bill.StatusChangeTime); values.Add("@Currency", bill.Currency); values.Add("@AdvanceDeadline", bill.AdvanceTimeLimit); values.Add("@MainDeadline", bill.MainTimeLimit); if (wmBill != null) { cmdBuilder = cmdBuilder.Replace("@DetailsId", "IDENT_CURRENT('Webmoney_Details') + 1"); cmdBuilder.Append("INSERT INTO Webmoney_Details VALUES(@Purse);"); values.Add("@Type", "WEBMONEY"); values.Add("@Purse", wmBill.WM_Purse); } else if (pbBill != null) { cmdBuilder = cmdBuilder.Replace("@DetailsId", "IDENT_CURRENT('Bank_Details') + 1"); cmdBuilder.Append("INSERT INTO Bank_Details VALUES(@Account, @EDRPOU, @MFO);"); values.Add("@Type", "BANK"); values.Add("@Account", pbBill.Account); values.Add("@EDRPOU", pbBill.EDRPOU); values.Add("@MFO", pbBill.MFO); } SqlCommand cmd = new SqlCommand(cmdBuilder.ToString(), connection); foreach (var kvp in values) { cmd.Parameters.AddWithValue(kvp.Key, kvp.Value); } connection.Open(); SqlTransaction transaction = connection.BeginTransaction(); cmd.Transaction = transaction; try { cmd.ExecuteNonQuery(); transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message)); } } return(Request.CreateResponse(HttpStatusCode.OK, "OK")); }