public ActionResult AddUpdate(int?id)
        {
            var model = new etblRoomRateRangeM();

            model.iRoomRateRangeId = 0;

            if (id.HasValue)
            {
                model = BL_RoomRateRangeM.GetRateRangeById(id.Value);
            }

            return(PartialView("_AddUpdate", model));
        }
        public ActionResult AddUpdate(etblRoomRateRangeM model)
        {
            try
            {
                string message = string.Empty;

                if (ModelState.IsValid)
                {
                    model.dtActionDate = DateTime.Now;
                    model.iActionBy    = ((BL_Login.UserDetails)Session["UserDetails"]).iUserId;
                    model.dAmountFrom  = model.dAmountFrom;
                    model.dAmountTo    = model.dAmountTo;

                    var result = BL_RoomRateRangeM.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));
            }
        }
Beispiel #3
0
        public static KeyValuePair <int, string> AddOrUpdate(etblRoomRateRangeM model)
        {
            try
            {
                var dbModel = new tblRoomRateRangeM();

                using (OneFineRateEntities db = new OneFineRateEntities())
                {
                    if (model.iRoomRateRangeId.HasValue && model.iRoomRateRangeId.Value != 0)
                    {
                        var duplicateCount = db.tblRoomRateRangeMs
                                             .Any(x => x.iRangeId != model.iRoomRateRangeId &&
                                                  ((model.dAmountFrom >= x.dAmountFrom && model.dAmountFrom <= x.dAmountTo) ||
                                                   (model.dAmountTo >= x.dAmountFrom && model.dAmountTo <= x.dAmountTo) ||
                                                   (model.dAmountFrom <= x.dAmountFrom && model.dAmountTo >= x.dAmountTo)));

                        if (duplicateCount)
                        {
                            return(new KeyValuePair <int, string>(-1, "Overlapping range can not be assigned!"));
                        }

                        dbModel.iRangeId = model.iRoomRateRangeId.Value;
                    }
                    else
                    {
                        var duplicateCount = db.tblRoomRateRangeMs
                                             .Any(x => (model.dAmountFrom >= x.dAmountFrom && model.dAmountFrom <= x.dAmountTo) ||
                                                  (model.dAmountTo >= x.dAmountFrom && model.dAmountTo <= x.dAmountTo) ||
                                                  (model.dAmountFrom <= x.dAmountFrom && model.dAmountTo >= x.dAmountTo));

                        if (duplicateCount)
                        {
                            return(new KeyValuePair <int, string>(-1, "Overlapping range can not be assigned!"));
                        }
                    }

                    //var duplicateCount = db.tblRoomRateRangeMs.Any(x => x.iRangeId != model.iRoomRateRangeId
                    //   && (model.dAmountFrom>= x.dAmountFrom&&model.dAmountTo<x.dAmountTo));

                    //if (duplicateCount)
                    //{
                    //    return new KeyValuePair<int, string>(-1, "This amount range has already been assigned!");
                    //}

                    dbModel.iRangeId     = model.iRoomRateRangeId.Value;
                    dbModel.cStatus      = model.cStatus;
                    dbModel.dtActionDate = model.dtActionDate;
                    dbModel.dAmountFrom  = model.dAmountFrom;
                    dbModel.dAmountTo    = model.dAmountTo;
                    dbModel.iActionBy    = model.iActionBy.Value;

                    if (dbModel.iRangeId > 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.tblRoomRateRangeMs.Add(dbModel);
                        db.SaveChanges();
                        return(new KeyValuePair <int, string>(1, "Record has been updated successfully!"));
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }