asp.net - How to change value of table column (Status) from available to booked after [HttpPost] in mvc 4 entity framework code first? -
i want book property , display status of property available booked. how can this? available classes below. first want show booking table, after inserting data booking table, next table want show payment table.if value of paymenttype(enum) fullpayment property booked , status of booked stored in database across booked property , displayed in view. if paymenttype(enum) installment installment table view shown installment process proceed...please me implement scenario. must explain how installment process continued. if there wrong models suggest correct model also. installment class contains installmentid,paymentid, installmentamount, actualamount, remaninigamount, numofinstallments, paidinstallment, remaininginstallment , installmenttitle [table("property")] public class property { [key] [databasegenerated(databasegeneratedoption.identity)] public int propertyid { get; set; } public propertytype propertytype { get; set; } public int streetid { get; set; } public int sectorid { get; set; } public int phaseid { get; set; } public string size { get; set; } public int price { get; set; } public status status { get; set; } public string propertytitle { get; set; } public virtual street street { get; set; } public virtual sector sector { get; set; } public virtual phase phase { get; set; } } [table("payment")] public class payment { [key] [databasegenerated(databasegeneratedoption.identity)] public int paymentid { get; set; } public paymenttype paymenttype { get; set; } public int bookingid { get; set; } public int totalamount { get; set; } public string bankname { get; set; } public long accountnumber { get; set; } [displayformat(dataformatstring = "{0:yyyy-mm-dd}", applyformatineditmode = true)] [datatype(datatype.date)] public datetime paymentdate { get; set; } public string paymenttitle { get; set; } public icollection<installment> installments { get; set; } public virtual booking booking { get; set; } } [table("booking")] public class booking { [key] [databasegenerated(databasegeneratedoption.identity)] public int bookingid { get; set; } public int propertyid { get; set; } [display(name="member cnic")] public string cnic { get; set; } public string bookingtitle { get; set; } public virtual property property { get; set; } public virtual member member { get; set; } }
this payment controller , controller want change value of status column available booked in property table
[httppost] [validateantiforgerytoken] public actionresult create([bind(include="paymentid,paymenttype,bookingid,totalamount,bankname,accountnumber,paymenttitle,paymentdate")] payment payment) { db.payments.add(payment); db.savechanges(); if (payment.paymenttype == paymenttype.installment) { return redirecttoaction("create", "installment"); } else { redirecttoaction("index", "property"); } viewbag.paymentid = new selectlist(db.payments, "paymentid", "paymentid", payment.paymentid); viewbag.bookingid = new selectlist(db.payments, "bookingid", "bookingid", payment.bookingid); return view(); }
i tried query it's not working
var bc = db.property.where(a => a.status == status.available);
i think property
table has foreign key of paymentid.
after payment created select property payment id
[httppost] [validateantiforgerytoken] public actionresult create([bind(include="paymentid,paymenttype,bookingid,totalamount,bankname,accountnumber,paymenttitle,paymentdate")] payment payment) { db.payments.add(payment); db.savechanges(); var property = db.property.where(a=>a.paymentid == payment.paymentid).firstordefault(); // if got multiple property 1 payment use tolist() instead of firstordefault() property.status == "available"; // change status here context.entry(property).state = entitystate.modified; db.savechanges(); // save property // rest of code if (payment.paymenttype == paymenttype.installment) { return redirecttoaction("create", "installment"); } else { redirecttoaction("index", "property"); } viewbag.paymentid = new selectlist(db.payments, "paymentid", "paymentid", payment.paymentid); viewbag.bookingid = new selectlist(db.payments, "bookingid", "bookingid", payment.bookingid); return view(); }
Comments
Post a Comment