예제 #1
0
        public RoomTO Update(RoomTO Entity)
        {
            if (Entity is null)
            {
                throw new ArgumentNullException(nameof(Entity));
            }

            var attachedRoom = facilityContext.Rooms.FirstOrDefault(x => x.Id == Entity.Id && x.Archived != true);

            if (attachedRoom != default)
            {
                attachedRoom.UpdateFromDetached(Entity.ToEF());
            }

            if (!facilityContext.Rooms.Any(x => x.Id == Entity.Id))
            {
                throw new KeyNotFoundException("No room found !");
            }

            var tracking = facilityContext.Rooms.Update(attachedRoom);

            tracking.State = EntityState.Detached;
            //var entity = facilityContext.Rooms.Update(attachedRoom).Entity.ToTransfertObject();
            //facilityContext.SaveChanges();
            return(tracking.Entity.ToTransfertObject());
        }
예제 #2
0
        public RoomTO Add(RoomTO Entity)
        {
            if (Entity is null)
            {
                throw new ArgumentNullException(nameof(Entity));
            }

            var roomEf = Entity.ToEF();

            roomEf.Floor = facilityContext.Floors.First(x => x.Id == Entity.Floor.Id && x.Archived != true);

            return(facilityContext.Rooms.Add(roomEf).Entity.ToTransfertObject());
        }