Ejemplo n.º 1
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
                }));
            }
        }