/// <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); }