/// <summary> /// Creates new room type or updates the existing one /// </summary> /// <param name="request"></param> /// <param name="userName"></param> /// <returns>Task<BaseResult<List<Room>>></returns> public async Task <BaseResult <List <Room> > > SaveAndUpdateRoom(HotelRoomTypeViewModel request, string userName) { BaseResult <List <Room> > result = new BaseResult <List <Room> >() { Result = new List <Room>() { new Room() { Id = 0 } } }; if (request.ObjectState == ObjectState.Added) { DynamicParameters paramCollection = RoomRequestMapper.CreateRoomTypeParameters(request, userName); result = await iRoomLibrary.ExecuteStoredProcedure(Constants.StoredProcedure.CreateRoomType, paramCollection).ConfigureAwait(false); return(result); } else if (request.ObjectState == ObjectState.Modified) { if (request.RoomId <= default(int)) { result.IsError = true; result.ErrorCode = (int)coreHelper.Constants.ErrorCodes.NoRoomOfID; result.Message = string.Format(coreHelper.Constants.ErrorMessage.NoRoomOfID, request.RoomId); return(result); } var room = await iRoomLibrary.GetListByPredicate(x => x.Id == request.RoomId && x.HotelId == request.HotelId && !x.IsDeleted); if (room.IsError == true || room.ExceptionMessage != null) { result.ExceptionMessage = room.ExceptionMessage; result.IsError = room.IsError; return(result); } if (!room.Result.Any()) { result.IsError = true; result.ErrorCode = (int)coreHelper.Constants.ErrorCodes.NoRoomOfID; result.Message = string.Format(coreHelper.Constants.ErrorMessage.NoRoomOfID, request.RoomId); return(result); } var updatedRoom = RoomRequestMapper.AutoMapperRoom(request, room.Result[0], userName); var updateResult = await iRoomLibrary.UpdateEntityByDapper(updatedRoom).ConfigureAwait(false); if (updateResult.IsError || updateResult.ExceptionMessage != null) { result.IsError = true; result.ExceptionMessage = updateResult.ExceptionMessage; return(result); } else if (updateResult == null) { result = null; return(result); } if (updateResult.Result == true) { result.Result[0].Id = updatedRoom.Id; } return(result); } else { var room = await iRoomLibrary.GetListByPredicate(x => x.Id == request.RoomId && x.HotelId == request.HotelId && !x.IsDeleted); return(room); } return(result); }
/// <summary> /// Creates Room bed Relation or updates the existing one /// </summary> /// <param name="request"></param> /// <param name="hotelRoomId"></param> /// <param name="userName"></param> /// <returns>Task<BaseResult<RoomBedRelation>></returns> public async Task <BaseResult <RoomBedRelation> > SaveAndUpdateRoomBedRelation(HotelRoomTypeViewModel request, int hotelRoomId, string userName) { BaseResult <RoomBedRelation> result = new BaseResult <RoomBedRelation>(); result.Result = new RoomBedRelation(); var update = false; if (request.RoomBedOptions.ObjectState == ObjectState.Added) { var list = RoomRequestMapper.CreateRoomBedRelation(request, hotelRoomId, userName); var insertResult = await iRoomBedRelationLibrary.InsertEntityList(list.Result).ConfigureAwait(false); if (insertResult.IsError && insertResult.ExceptionMessage != null) { result.IsError = insertResult.IsError; result.ExceptionMessage = insertResult.ExceptionMessage; return(result); } result.Result.ID = (int)insertResult.Result; return(result); } if (request.RoomBedOptions.ObjectState == ObjectState.Modified || request.RoomBedOptions.ObjectState == ObjectState.Unchanged) { foreach (var item in request.RoomBedOptions.RoomBedList) { if (item.ObjectState == ObjectState.Modified && item.ID > 0) { var oldItem = await iRoomBedRelationLibrary.GetListByPredicate(x => x.ID == item.ID && !x.IsDeleted); if (result.IsError || oldItem.ExceptionMessage != null) { result.IsError = true; result.ExceptionMessage = oldItem.ExceptionMessage; return(result); } if (oldItem != null && oldItem.Result.Any()) { var newRoomBed = RoomRequestMapper.AutoMapperRoomBedRelation(item, oldItem.Result[0], userName); var updateResult = await iRoomBedRelationLibrary.UpdateEntityByDapper(newRoomBed).ConfigureAwait(false); if (updateResult.IsError || updateResult.ExceptionMessage != null) { result.IsError = true; result.ExceptionMessage = updateResult.ExceptionMessage; return(result); } else if (updateResult == null) { result = null; return(result); } if (updateResult.Result == true) { result.Result.ID = newRoomBed.ID; } } } else if (item.ObjectState == ObjectState.Added && item.ID == 0) { var list = RoomRequestMapper.MapRoomBedRelationEntity(request, item, hotelRoomId, userName); var insertResult = await iRoomBedRelationLibrary.InsertEntity(list.Result).ConfigureAwait(false); if (insertResult.IsError || insertResult.ExceptionMessage != null) { result.IsError = true; result.ExceptionMessage = insertResult.ExceptionMessage; return(result); } else if (insertResult == null) { result = null; return(result); } result.Result.ID = (int)insertResult.Result; } } //var roomBedList = await iRoomBedRelationLibrary.GetListByPredicate(x => x.HotelRoomId == hotelRoomId && !x.IsDeleted).ConfigureAwait(false); var room = await iRoomLibrary.GetEntity(hotelRoomId); if (room.IsError && room.ExceptionMessage != null) { result.IsError = true; result.ExceptionMessage = room.ExceptionMessage; return(result); } if (request.RoomBedOptions.RoomBedList.Any(x => x.BedId == (int)BedTypes.King || x.BedId == (int)BedTypes.Queen)) { if (room.Result.IsTwin) { room.Result.IsTwin = false; update = true; } } else { if (!room.Result.IsTwin) { room.Result.IsTwin = true; update = true; } } if (update == true) { room.Result.UpdatedBy = userName; room.Result.UpdatedDate = DateTime.Now.JakartaOffset(); var secResult = await iRoomLibrary.UpdateEntityByDapper(room.Result); if (secResult.IsError && secResult.ExceptionMessage != null) { result.IsError = secResult.IsError; result.ExceptionMessage = secResult.ExceptionMessage; return(result); } } } return(result); }
/// <summary> /// Creates Room bed Relation or updates the existing one /// </summary> /// <param name="request"></param> /// <param name="hotelRoomId"></param> /// <param name="userName"></param> /// <returns>Task<BaseResult<RoomBedRelation>></returns> public async Task <BaseResult <RoomBedRelation> > SaveAndUpdateRoomBedRelation(HotelRoomTypeViewModel request, int hotelRoomId, string userName) { BaseResult <RoomBedRelation> result = new BaseResult <RoomBedRelation>(); result.Result = new RoomBedRelation(); if (request.RoomBedOptions.ObjectState == ObjectState.Added) { var list = RoomRequestMapper.CreateRoomBedRelation(request, hotelRoomId, userName); var insertResult = await iRoomBedRelationLibrary.InsertEntityList(list.Result).ConfigureAwait(false); if (insertResult.IsError && insertResult.ExceptionMessage != null) { result.IsError = insertResult.IsError; result.ExceptionMessage = insertResult.ExceptionMessage; return(result); } result.Result.ID = (int)insertResult.Result; return(result); } if (request.RoomBedOptions.ObjectState == ObjectState.Modified || request.RoomBedOptions.ObjectState == ObjectState.Unchanged) { foreach (var item in request.RoomBedOptions.RoomBedList) { if (item.ObjectState == ObjectState.Modified && item.ID > 0) { var oldItem = await iRoomBedRelationLibrary.GetListByPredicate(x => x.ID == item.ID && !x.IsDeleted); if (result.IsError || oldItem.ExceptionMessage != null) { result.IsError = true; result.ExceptionMessage = oldItem.ExceptionMessage; return(result); } if (oldItem != null && oldItem.Result.Any()) { var newRoomBed = RoomRequestMapper.AutoMapperRoomBedRelation(item, oldItem.Result[0], userName); var updateResult = await iRoomBedRelationLibrary.UpdateEntityByDapper(newRoomBed).ConfigureAwait(false); if (updateResult.IsError || updateResult.ExceptionMessage != null) { result.IsError = true; result.ExceptionMessage = updateResult.ExceptionMessage; return(result); } else if (updateResult == null) { result = null; return(result); } if (updateResult.Result == true) { result.Result.ID = newRoomBed.ID; } } } else if (item.ObjectState == ObjectState.Added && item.ID == 0) { var list = RoomRequestMapper.MapRoomBedRelationEntity(request, item, hotelRoomId, userName); var insertResult = await iRoomBedRelationLibrary.InsertEntity(list.Result).ConfigureAwait(false); if (insertResult.IsError || insertResult.ExceptionMessage != null) { result.IsError = true; result.ExceptionMessage = insertResult.ExceptionMessage; return(result); } else if (insertResult == null) { result = null; return(result); } result.Result.ID = (int)insertResult.Result; } //else //{ // result.IsError = true; // result.ErrorCode = (int)coreHelper.Constants.ErrorCodes.NoRoomBedRelationOfID; // result.Message = string.Format(coreHelper.Constants.ErrorMessage.NoRoomBedRelationOfID,item.ID); // return result; //} } return(result); } return(result); }