コード例 #1
0
        public string AddUpdateRoomFeaturesMapping(RoomFeaturesMappingVM model)
        {
            string id = string.Empty;

            SqlParameter[] parameters =
            {
                new SqlParameter {
                    ParameterName = "@RoomId", Value = model.RoomId
                },
                new SqlParameter {
                    ParameterName = "@RoomFeatureId", Value = model.RoomFeatureId
                },
                new SqlParameter {
                    ParameterName = "@CreatedBy", Value = model.CreatedBy
                },
                new SqlParameter {
                    ParameterName = "@UpdatedBy", Value = model.UpdatedBy
                }
            };

            id = Convert.ToString(DALHelper.ExecuteScalar("AddUpdateRoomFeaturesMapping", parameters));

            return(id);
        }
コード例 #2
0
        public ActionResult Edit(RoomVM model)
        {
            try
            {
                string roomId = string.Empty;
                model.UpdatedBy = LogInManager.LoggedInUserId;

                #region Check Room No Available.

                if (this.CheckRoomNoAvailable(model.Id, model.RoomNo) == false)
                {
                    return(Json(new
                    {
                        IsSuccess = false,
                        errorMessage = string.Format("Room No : {0} already exist.", model.RoomNo)
                    }, JsonRequestBehavior.AllowGet));
                }

                #endregion

                model.StatusId = Guid.Parse(RoomStatusType.CLEAN);
                roomId         = roomRepository.UpdateRoom(model);

                if (!string.IsNullOrWhiteSpace(roomId))
                {
                    #region Delete Room Features

                    var roomFeatures = roomRepository.GetRoomFeaturesMapping(Guid.Parse(roomId), null);

                    if (roomFeatures != null && roomFeatures.Count > 0)
                    {
                        List <Guid> mappingIds = new List <Guid>();
                        foreach (var roomFeature in roomFeatures)
                        {
                            if (roomFeature.RoomFeatureId.HasValue)
                            {
                                if (model.RoomFeatures == null || !model.RoomFeatures.Contains(roomFeature.RoomFeatureId.Value))
                                {
                                    mappingIds.Add(roomFeature.Id);
                                }
                            }
                        }

                        //Delete Room Features
                        if (mappingIds != null && mappingIds.Count > 0)
                        {
                            foreach (var id in mappingIds)
                            {
                                roomRepository.DeleteRoomFeaturesMapping(id, LogInManager.LoggedInUserId);
                            }
                        }
                    }
                    #endregion

                    #region Add / Update Room Features

                    if (model.RoomFeatures != null && model.RoomFeatures.Count > 0)
                    {
                        foreach (var item in model.RoomFeatures)
                        {
                            RoomFeaturesMappingVM roomFeaturesMapping = new RoomFeaturesMappingVM();
                            roomFeaturesMapping.RoomId        = Guid.Parse(roomId);
                            roomFeaturesMapping.RoomFeatureId = item;
                            roomFeaturesMapping.CreatedBy     = LogInManager.LoggedInUserId;
                            roomFeaturesMapping.UpdatedBy     = LogInManager.LoggedInUserId;

                            roomRepository.AddUpdateRoomFeaturesMapping(roomFeaturesMapping);
                        }
                    }
                    #endregion

                    return(Json(new
                    {
                        IsSuccess = true,
                        data = new
                        {
                            RoomId = roomId,
                            Room = model
                        }
                    }, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    return(Json(new
                    {
                        IsSuccess = false,
                        errorMessage = "Room details not updated successfully."
                    }, JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception e)
            {
                Utility.Utility.LogError(e, "Edit");
                return(Json(new
                {
                    IsSuccess = false,
                    errorMessage = e.Message
                }));
            }
        }
コード例 #3
0
        public ActionResult Create(RoomVM model)
        {
            try
            {
                string roomId = string.Empty;
                model.CreatedBy = LogInManager.LoggedInUserId;

                #region Check Room No Available.

                if (this.CheckRoomNoAvailable(model.Id, model.RoomNo) == false)
                {
                    return(Json(new
                    {
                        IsSuccess = false,
                        errorMessage = string.Format("Room No : {0} already exist.", model.RoomNo)
                    }, JsonRequestBehavior.AllowGet));
                }

                #endregion

                model.StatusId = Guid.Parse(RoomStatusType.CLEAN);
                roomId         = roomRepository.AddRoom(model);

                if (!string.IsNullOrWhiteSpace(roomId))
                {
                    model.Id = Guid.Parse(roomId);

                    #region Update Floor (No. Of Rooms)

                    //Increase the no. of rooms quantity in floor.
                    var floor = floorRepository.GetFloorById(model.FloorId).FirstOrDefault();

                    if (floor != null)
                    {
                        floor.NoOfRoom = floor.NoOfRoom > 0 ? (floor.NoOfRoom + 1) : 0;

                        floorRepository.UpdateFloor(floor);
                    }

                    #endregion


                    #region Add Room Features

                    if (model.RoomFeatures != null && model.RoomFeatures.Count > 0)
                    {
                        foreach (var item in model.RoomFeatures)
                        {
                            RoomFeaturesMappingVM roomFeaturesMapping = new RoomFeaturesMappingVM();
                            roomFeaturesMapping.RoomId        = Guid.Parse(roomId);
                            roomFeaturesMapping.RoomFeatureId = item;
                            roomFeaturesMapping.CreatedBy     = LogInManager.LoggedInUserId;
                            roomFeaturesMapping.UpdatedBy     = LogInManager.LoggedInUserId;

                            roomRepository.AddUpdateRoomFeaturesMapping(roomFeaturesMapping);
                        }
                    }
                    #endregion

                    return(Json(new
                    {
                        IsSuccess = true,
                        data = new
                        {
                            RoomId = roomId,
                            Room = model
                        }
                    }, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    return(Json(new
                    {
                        IsSuccess = false,
                        errorMessage = "Room details not saved successfully."
                    }, JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception e)
            {
                Utility.Utility.LogError(e, "Create");

                return(Json(new
                {
                    IsSuccess = false,
                    errorMessage = e.Message
                }));
            }
        }