public dynamic AddProperty(dynamic property) { db.Configuration.ProxyCreationEnabled = false; var httpRequest = System.Web.HttpContext.Current.Request; PROPERTY prop = new PROPERTY(); try { // string areaname = property.AREA; // string propertype = property.PROPERTYTYPE; // AREA area = db.AREAs.Where(zz => zz.AREANAME == areaname).FirstOrDefault(); // PROPERTYTYPE type = db.PROPERTYTYPEs.Where(zz => zz.PROPERTTYPEDESCRIPTION == propertype).FirstOrDefault(); prop.AREAID = property.AREA; prop.PROPERTYTYPEID = property.PROPERTYTYPE; prop.PROPERTYDESCRIPTION = property.PROPERTYDESCRIPTION; prop.ADDRESS = property.ADDRESS; prop.SIZE = property.SIZE; prop.NUMBED = property.NUMBED; prop.NUMBBATH = property.NUMBBATH; prop.GARDEN = property.GARDEN; prop.ADDITIONALINFO = property.ADDITIONALINFO; prop.PROPERTYSTATUSID = 1; prop.LISTINGDATE = DateTime.Now.Date; prop.AVAILABLEDATE = property.AVAILABLEDATE; prop.IsExtending = false; db.PROPERTies.Add(prop); db.SaveChanges(); } catch (Exception) { return(null); } try { RENTALAMOUNT amnt = new RENTALAMOUNT(); int propertyId = int.Parse(db.PROPERTies .OrderByDescending(p => p.PROPERTYID) .Select(r => r.PROPERTYID) .First().ToString()); amnt.PROPERTYID = propertyId; amnt.AMOUNT = property.RENTALAMOUNT; amnt.DATE = DateTime.Today; db.RENTALAMOUNTs.Add(amnt); db.SaveChanges(); } catch (Exception) { return(null); } return(true); }
public IHttpActionResult DeletePropertyDelete(int id) { try { PROPERTY property = db.PROPERTies.Find(id); if (property == null) { return(NotFound()); } else { RENTALAMOUNT amnt = db.RENTALAMOUNTs.Where(hh => hh.PROPERTYID == property.PROPERTYID).FirstOrDefault(); if (amnt != null) { db.RENTALAMOUNTs.Remove(amnt); db.SaveChanges(); } List <PROPERTYPHOTO> photos = db.PROPERTYPHOTOes.Where(jj => jj.PROPERTYID == property.PROPERTYID).ToList(); if (photos.Count != 0) { foreach (PROPERTYPHOTO photo in photos) { db.PROPERTYPHOTOes.Remove(photo); db.SaveChanges(); } } else { } db.PROPERTies.Remove(property); db.SaveChanges(); } return(Ok(property)); } catch (Exception) { return(null); } }
public dynamic PutPropertyMaster(dynamic property) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { int ID = property.PROPERTYID; PROPERTY objEmp = new PROPERTY(); objEmp = db.PROPERTies.Where(ww => ww.PROPERTYID == ID).FirstOrDefault(); if (objEmp != null) { string areaname = property.AREA; string propertype = property.PROPERTYTYPE; AREA area = db.AREAs.Where(zz => zz.AREANAME == areaname).FirstOrDefault(); PROPERTYTYPE type = db.PROPERTYTYPEs.Where(zz => zz.PROPERTTYPEDESCRIPTION == propertype).FirstOrDefault(); objEmp.AREAID = property.AREA; objEmp.PROPERTYTYPEID = property.PROPERTYTYPE; // objEmp.PROPERTYSTATUSID = property.PROPERTYSTATUSID; ///objEmp.AGENT_ID = property.AGENT_ID; objEmp.PROPERTYDESCRIPTION = property.PROPERTYDESCRIPTION; objEmp.ADDRESS = property.ADDRESS; objEmp.SIZE = property.SIZE; objEmp.NUMBBATH = property.NUMBBATH; objEmp.NUMBED = property.NUMBED; objEmp.GARDEN = property.GARDEN; objEmp.ADDITIONALINFO = property.ADDITIONALINFO; objEmp.AVAILABLEDATE = property.AVAILABLEDATE; db.SaveChanges(); RENTALAMOUNT amnt = new RENTALAMOUNT(); amnt = db.RENTALAMOUNTs.Where(qq => qq.PROPERTYID == objEmp.PROPERTYID).FirstOrDefault(); amnt.AMOUNT = property.RENTALAMOUNT; amnt.DATE = DateTime.Today; db.SaveChanges(); } } catch (Exception) { return(null); } return(Ok(property)); }