public static eServiceChargeM GetOfrServiceCharge(DateTime checkIn, DateTime checkOut) { var model = new eServiceChargeM(); using (OneFineRateEntities db = new OneFineRateEntities()) { var record = db.tblServiceChargeMs.Where(x => DbFunctions.TruncateTime(checkIn) >= DbFunctions.TruncateTime(x.dtFrom) && DbFunctions.TruncateTime(checkOut) <= DbFunctions.TruncateTime(x.dtTo) && x.cStatus == "A").FirstOrDefault(); if (record != null) { model.ServiceChargeTG = record.dServiceCharge; if (record.cGstValueType == "p") { model.GstOnServiceChargeTG = (record.dServiceCharge * record.dGstValue) / 100; model.GstOnServiceChargePercentTG = record.dGstValue; } else { model.GstOnServiceChargeTG = record.dGstValue; model.GstOnServiceChargePercentTG = (record.dGstValue / record.dServiceCharge) * 100; } model.TotalServiceChargeTG = model.ServiceChargeTG + model.GstOnServiceChargeTG; model.GstValue = record.dGstValue; model.GstValueType = record.cGstValueType; } return(model); } }
public ActionResult AddUpdate(int?id) { var model = new eServiceChargeM(); model.ServiceChargeId = 0; if (id.HasValue) { model = BL_ServiceChargeM.GetServiceChargeById(id.Value); } return(PartialView("_AddUpdate", model)); }
public ActionResult AddUpdate(eServiceChargeM model) { try { string message = string.Empty; if (ModelState.IsValid) { model.ActionDate = DateTime.Now; model.ActionById = ((BL_Login.UserDetails)Session["UserDetails"]).iUserId; model.dtFrom = DateTime.ParseExact(model.From, "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture); model.dtTo = DateTime.ParseExact(model.To, "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture); var result = BL_ServiceChargeM.AddOrUpdate(model); if (result.Key == -1) { return(Json(new { status = false, Msg = result.Value }, JsonRequestBehavior.AllowGet)); } else if (result.Key == 1) { return(Json(new { status = true, Msg = result.Value }, JsonRequestBehavior.AllowGet)); } return(Json(new { status = true, Msg = message }, JsonRequestBehavior.AllowGet)); } message = string.Join(" | ", ModelState.Values.SelectMany(v => v.Errors).Select(e => e.ErrorMessage)); return(Json(new { status = false, Msg = message }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(Json(new { status = false, Msg = "An error occured while adding the record, Kindly try after some time." }, JsonRequestBehavior.AllowGet)); } }
public static KeyValuePair <int, string> AddOrUpdate(eServiceChargeM model) { try { var dbModel = new tblServiceChargeM(); using (OneFineRateEntities db = new OneFineRateEntities()) { if (model.ServiceChargeId.HasValue && model.ServiceChargeId.Value != 0) { var duplicateCount = db.tblServiceChargeMs.Any(x => x.iServiceChargeId != model.ServiceChargeId && ((model.dtFrom >= x.dtFrom && model.dtFrom <= x.dtTo) || (model.dtTo >= x.dtFrom && model.dtTo <= x.dtTo) || (model.dtFrom <= x.dtFrom && model.dtTo >= x.dtTo)) && x.cStatus == "A"); if (duplicateCount) { return(new KeyValuePair <int, string>(-1, "Overlapping date range can not be assigned!")); } dbModel.iServiceChargeId = model.ServiceChargeId.Value; } else { var duplicateCount = db.tblServiceChargeMs.Any(x => ((model.dtFrom >= x.dtFrom && model.dtFrom <= x.dtTo) || (model.dtTo >= x.dtFrom && model.dtTo <= x.dtTo) || (model.dtFrom <= x.dtFrom && model.dtTo >= x.dtTo)) && x.cStatus == "A"); if (duplicateCount) { return(new KeyValuePair <int, string>(-1, "Overlapping date range can not be assigned!")); } } dbModel.cGstValueType = model.GstValueType; dbModel.cStatus = model.Status; dbModel.dGstValue = model.GstValue; dbModel.dServiceCharge = model.ServiceCharge; dbModel.dtActionDate = model.ActionDate; dbModel.dtFrom = DateTime.ParseExact(model.From, "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture); dbModel.dtTo = DateTime.ParseExact(model.To, "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture); dbModel.iActionBy = model.ActionById.Value; if (dbModel.iServiceChargeId > 0) { db.Entry(dbModel).State = EntityState.Modified; db.SaveChanges(); return(new KeyValuePair <int, string>(1, "Record has been added successfully!")); } else { dbModel.cStatus = "A"; db.tblServiceChargeMs.Add(dbModel); db.SaveChanges(); return(new KeyValuePair <int, string>(1, "Record has been updated successfully!")); } } } catch (Exception) { throw; } }