//Update a record public static int UpdateRecord(etblPropertyRoomRatePlanInventoryMap eobj) { int retval = 0; using (OneFineRateEntities db = new OneFineRateEntities()) { try { //remove old mapings db.tblPropertyRoomRatePlanInventoryMaps.RemoveRange(db.tblPropertyRoomRatePlanInventoryMaps.Where(x => x.iRoomId == eobj.iRoomId && x.dtInventoryDate == eobj.dtInventoryDate && x.iRPId == eobj.iRPId)); OneFineRate.tblPropertyRoomRatePlanInventoryMap obj = (OneFineRate.tblPropertyRoomRatePlanInventoryMap)OneFineRateAppUtil.clsUtils.ConvertToObject(eobj, new OneFineRate.tblPropertyRoomRatePlanInventoryMap()); db.tblPropertyRoomRatePlanInventoryMaps.Add(obj); db.SaveChanges(); retval = 1; } catch (Exception) { throw; } } return(retval); }
//Get Single Record public static etblPropertyRoomRatePlanInventoryMap GetSingleRecordById(int roomid, int rateplanid, DateTime inventorydate) { etblPropertyRoomRatePlanInventoryMap eobj = new etblPropertyRoomRatePlanInventoryMap(); using (OneFineRateEntities db = new OneFineRateEntities()) { var dbobj = (from t2 in db.tblPropertyRatePlanMaps join t1 in db.tblPropertyRoomRatePlanInventoryMaps on t2.iRPId equals t1.iRPId into S1 from a in S1.DefaultIfEmpty() join t3 in db.tblPropertyRoomMaps on a.iRoomId equals t3.iRoomId into S2 from b in S2.DefaultIfEmpty() select new { a.dtInventoryDate, a.iPropId, a.iRoomId, a.iRPId, a.bCloseOut, iMinLengthStay = a.iMinLengthStay == null ? t2.iMinLengthStay : a.iMinLengthStay, iMaxLengthStay = a.iMaxLengthStay == null ? t2.iMaxLengthStay : a.iMaxLengthStay, a.bCTA, a.bCTD, a.dSingleRate, a.dDoubleRate, a.dTripleRate, a.dQuadrupleRate, a.dQuintrupleRate, a.dtActionDate, iActionBy = t2.bLinkToExistingRatePlan == true ? 1 : 0, t2.sRatePlan, b.sRoomName }).Where(u => u.dtInventoryDate == inventorydate && u.iRoomId == roomid && u.iRPId == rateplanid).AsQueryable().SingleOrDefault(); if (dbobj == null) { var NewdbObj = (from t2 in db.tblPropertyRatePlanMaps join t3 in db.tblPropertyRoomMaps on t2.iPropId equals t3.iPropId into S2 from b in S2.DefaultIfEmpty() select new { iActionBy = t2.bLinkToExistingRatePlan == true ? 1 : 0, t2.sRatePlan, b.sRoomName, b.iRoomId, t2.iRPId }).Where(u => u.iRoomId == roomid && u.iRPId == rateplanid).AsQueryable().SingleOrDefault(); eobj = (etblPropertyRoomRatePlanInventoryMap)OneFineRateAppUtil.clsUtils.ConvertToObject(NewdbObj, eobj); } else { eobj = (etblPropertyRoomRatePlanInventoryMap)OneFineRateAppUtil.clsUtils.ConvertToObject(dbobj, eobj); } } return(eobj); }
public ActionResult RoomInventoryRatePlan(string roomid, string date, string planId) { etblPropertyRoomRatePlanInventoryMap obj = new etblPropertyRoomRatePlanInventoryMap(); obj = BL_tblPropertyRoomRatePlanInventoryMap.GetSingleRecordById(Convert.ToInt32(roomid), Convert.ToInt32(planId), clsUtils.ConvertyyyymmddtoDateTime(date)); if (obj.iPropId != 0) { if (obj.bCloseOut == true) { obj.sCloseOut = "On"; } else { obj.sCloseOut = "Off"; } if (obj.bCTA == true) { obj.sCTA = "On"; } else { obj.sCTA = "Off"; } if (obj.bCTD == true) { obj.sCTD = "On"; } else { obj.sCTD = "Off"; } } obj.iRoomId = Convert.ToInt64(roomid); obj.iRPId = Convert.ToInt32(planId); obj.dtInventoryDate = clsUtils.ConvertyyyymmddtoDateTime(date); return(PartialView("_RoomInventoryRatePlan", obj)); }
public ActionResult AddUpdateRatePlan(etblPropertyRoomRatePlanInventoryMap eObj) { object result = null; try { if (ModelState.IsValid) { eObj.iPropId = Convert.ToInt32(Session["PropId"]); eObj.iActionBy = ((OneFineRateBLL.BL_Login.UserDetails)Session["UserDetails"]).iUserId; eObj.dtActionDate = DateTime.Now; if (eObj.SelectedOccupancies != null) { JArray jArray = (JArray)JsonConvert.DeserializeObject(eObj.SelectedOccupancies.Replace("\\", "\"")); if (jArray != null) { List <etblPropertyParkingMap> lstPropertyParkingMap = new List <etblPropertyParkingMap>(); foreach (var item in jArray) { if (Convert.ToInt32(item["type"]) == 1) { eObj.dSingleRate = Convert.ToDecimal(item["value"]); } if (Convert.ToString(item["type"]) == "2") { eObj.dDoubleRate = Convert.ToDecimal(item["value"]); } if (Convert.ToString(item["type"]) == "3") { eObj.dTripleRate = Convert.ToDecimal(item["value"]); } if (Convert.ToString(item["type"]) == "4") { eObj.dQuadrupleRate = Convert.ToDecimal(item["value"]); } if (Convert.ToString(item["type"]) == "5") { eObj.dQuintrupleRate = Convert.ToDecimal(item["value"]); } } } } string strReturn = BL_bulk.SaveInventory(((OneFineRateBLL.BL_Login.UserDetails)Session["UserDetails"]).iUserId, Convert.ToInt32(Session["PropId"]), eObj.dtInventoryDate.ToString("MM/dd/yyyy").Replace("-", "/"), eObj.iRoomId.ToString(), eObj.iRoomId.ToString() + "-" + eObj.iRPId.ToString(), "", "", "", eObj.bCloseOut ? "On" : "Off", eObj.iMinLengthStay.ToString(), eObj.iMaxLengthStay.ToString(), eObj.bCTA ? "On" : "Off", eObj.bCTD ? "On" : "Off", eObj.dSingleRate.ToString(), eObj.dDoubleRate.ToString(), eObj.dTripleRate.ToString(), eObj.dQuadrupleRate.ToString(), eObj.dQuintrupleRate.ToString()); if (strReturn == "a") { result = new { st = 1, msg = "Updated successfully." }; } else if (strReturn.StartsWith("[")) { result = new { st = 0, msg = "Rate Plan is not valid for this date." }; } else { result = new { st = 0, msg = "Kindly try after some time." }; } } else { string errormsg = ""; foreach (ModelState modelState in ViewData.ModelState.Values) { foreach (ModelError error in modelState.Errors) { errormsg += error.ErrorMessage; errormsg += "</br>"; } } result = new { st = 0, msg = errormsg }; } } catch (Exception) { result = new { st = 0, msg = "Kindly try after some time." }; } return(Json(result, JsonRequestBehavior.AllowGet)); }